Results 1 to 6 of 6

Thread: Cookie driven index page rotation

  1. #1
    Join Date
    Nov 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Cookie driven index page rotation

    Hey all,
    I'm looking for some basic enough code, but obviously beyond me at this stage.

    It seems it could be a javascript thing.

    I need an index page to load a cookie with the user so that each time they load the site they are brought to a different index page. There are five index pages and must load in a particular sequence, ie not randomly.

    If anyone has any examples of this working or any code it would be greatly appreciated!

    Many thanks!

  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

    Before anyone goes writing code for this, we should first clarify what you mean by:

    each time they load the site they are brought to a different index page. There are five index pages and must load in a particular sequence, ie not randomly
    This almost sounds too specific a task for javascript. For example, if javascript, or simply javascript cookies are disabled in the user's browsers, your 'must' will not happen. This also sounds like something that you would like to carry over across browser sessions. What this means is that say someone visits the site, closes their browser, then opens the browser and visits again - you would want the next index page in sequence to load. If I'm right about that, if javascript driven, the user may have all javascript cookies set to expire on browser close, so it would not work for those folks.

    Additionally, with javascript cookies, any given user may choose at any time to clear all javascript cookies from the browser with a few clicks or less.

    So, if this is really all that important, a server side solution would need to be worked out.

    If on the other hand, this is just something that you would like to have happen in most cases, javascript can do that. It would be a bit complicated and could have various approaches, but could still fairly easily be worked out. But, as I've implied, is not worth even thinking about in javascript if it 'must' happen.
    - John
    ________________________

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

  3. #3
    Join Date
    Nov 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I think its more a matter that, it would be great to get it working like this, rather than a cast iron solution.

    I think javasscript would be the simpler option and I think simplicity is the guiding factor here.

    Would you happen to have any code set up to work like that?

    Many thanks,

  4. #4
    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

    Here's a little demo. Each time the index page loads, it checks and sets a cookie to decide whether to remain on the index page or to switch to one of three other pages:

    Attachment 2264

    Let me know what you think, it's very basic and should be easy to modify if needed/desired. The only code that really matters (the cookie routines are all basic stuff for working with cookies) is:

    Code:
    var numPages = 3
    if(readCookie('whichPage') && readCookie('whichPage') !=0){
    window.location.replace('index' + readCookie('whichPage') + '.htm');
    createCookie('whichPage', (readCookie('whichPage') < numPages? readCookie('whichPage') - 0 + 1 : 0));
    }
    else
    createCookie('whichPage', 1)
    - John
    ________________________

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

  5. #5
    Join Date
    Dec 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    That works perfectly.

    How would I change it so, instead of rotating, it simply stops at the last page.

    In my case I just have two pages, and would like users to see the first page only once (kind of like an intro on a DVD that you only see the first time you put in the disc, before you get to the menu.)

    Thanks!

  6. #6
    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

    Say you have just index.htm and index1.htm, and index.htm is your 'splash page'. Change the code block from my previous post to:

    Code:
    if(readCookie('whichPage'))
    window.location.replace('index1.htm');
    else
    createCookie('whichPage', 1);
    But this isn't foolproof, as mentioned before in this thread, and it's not real SEO friendly either.
    - John
    ________________________

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

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
  •