Results 1 to 3 of 3

Thread: Virtual Pagination Cookies Possible?

  1. #1
    Join Date
    Jan 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Virtual Pagination Cookies Possible?

    1) Script Title: Virtual Pagination

    2) Script URL (on DD): http://dynamicdrive.com/dynamicindex...pagination.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!
    Last edited by wpthebest; 07-28-2007 at 12:28 AM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Demo:

    http://home.comcast.net/~jscheuer1/s...e/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:

    Code:
    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:

    Code:
    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:

    Code:
    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jan 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    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!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •