PDA

View Full Version : Virtual Pagination Cookies Possible?



wpthebest
07-28-2007, 12:13 AM
1) Script Title: Virtual Pagination

2) Script URL (on DD): http://dynamicdrive.com/dynamicindex17/virtualpagination.htm

3) Describe problem:

Would anyone know of a way I can create cookies that would save the last dropdown link in the pagination script that the user visited. Therefore, if they leave the page with the Virtual Pagination content and comeback to it later, it will be on the same item they were looking at?

As an example, on the virtual pagination script page, the fifth example layout has a dropdown with 4 images (Castle, Park, Harvest, Country). Okay, say I visit the Virtual Paginate page and I dropdown and select the "Harvest" tab. Now, say I left the virtual paginate script and went somewhere else like google or whatever. Now, when I return back to this Virtual Paginate page, would it possible to have had a cookie keep track of the last visited dropdown selection I had (i.e. Harvest) and load the page on this one where I had left off?

Thanks so much in advance!:confused:

jscheuer1
07-28-2007, 02:50 PM
Demo:

http://home.comcast.net/~jscheuer1/side/v_page/v_page_c.htm

I did this for one virtual pagination on a page. It could be worked out for as many as needed. No change was made to the virtualpaginate.js file. All additions were made in the body initialization script. Use your browser's "view source" to see the code.

Notes: If using this for more than one instance of virtual pagination on the page, you only need to add these functions once:


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

function readCookie(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;
}

Each instance would need its own:


if(readCookie('gallery_page')){
if(gallery.flatviewpresent)
gallery.flatviewlinks[gallery.currentpage].className=""
gallery.currentpage=readCookie('gallery_page')*1;
gallery.navigate(readCookie('gallery_page')*1);
}

following its initialization, with the word gallery changed to the variable name for that instance. It would also need to be added to the onunload event:


onunload=function(){
createCookie('gallery_page',gallery.currentpage,0)
}

by giving it its own createCookie line in that function and once again changing the word gallery to its variable name.

wpthebest
07-29-2007, 07:51 PM
jscheuer1,

This worked like a charm! Thank you so much for taking the time to not only explain, but also provide an example!

Warmest Regards!