Hi,

before I use $(‘#myScroll’).goToPage(whatever) to display that the ‘whatever’ page, is there a function to get the active pagenumber, so I can return to that original page later?

Thanks

asked Feb 22 at 18:45

Anonim's gravatar image

Anonim
211

edited Feb 24 at 09:27

Matteo%20Bicocchi's gravatar image

Matteo Bicocchi ♦♦
1071117


here is an example:

<div class="getIDX" onclick="alert($(‘#myScroll’).get(0).idx);">getIDX</div>

Supposed that your scrollable component ID is “myScroll”: clicking on the getIDX label should return the actual index page. You can make your own function that store the actual page index before calling the gotToPage function and than call again the goToPage() passing the stored idx as param:

$.fn.storeAndGo=function (pageNumber){
  $(this).get(0).actIDX= $(this).get(0).idx;
  $(this).goToPage(pageNumber);
}

Now you can make your own calls to this methods:

<div class="button" onclick="$('#myScroll').storeAndGo(5);">get IDX and go</div>
<div class="button" onclick="$('#myScroll').goToPage($('#myScroll').get(0).actIDX);">back to previous page</div>

If you want to store actual page-index in a cookie to get it once you come back to the page:

here there are three methods do manage cookies:

mb_setCookie = function(name,value,days) {
if (!days) days=7;
var date = new Date(), expires;
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires="+date.toGMTString();
document.cookie = name+"="+value+expires+"; path=/";
};

mb_getCookie = function(name) {
var nameEQ = name+ "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
};

mb_removeCookie = function(name) {
mb_setCookie(name,"",-1);
};

You can store the value in a cookie and get it once you are back in the page:

mb_setCookie('mbScrollableIDX', $('#myScroll').get(0).idx);

When you enter the page:

var mbScrollableStoredIDX= mb_getCookie('mbScrollableIDX');
if (typeOf mbScrollableStoredIDX != 'undefined')
$('#myScroll').goToPage(mbScrollableStoredIDX); 

answered Feb 22 at 18:47

Matteo%20Bicocchi's gravatar image

Matteo Bicocchi ♦♦
1071117

edited Feb 24 at 09:26

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×3
×1

Asked: Feb 22 at 18:45

Seen: 167 times

Last updated: Feb 24 at 09:27

powered by OSQA