Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript Session Cookie to remember last tab

    Hi,

    I have a website where the user can navigate different categories by tab. The problem is, when they're on a tab other than the default one and they refresh the page or click to another page, it puts them back on the first tab. I know this can be solved by using a session cookie of some type, I just need some help on implementing it into my site.

    http://www.thatswhyimbroke.com/ - so you can see what i'm talking about. If you look at the different tabs: Price High, price low, food & drink, etc. I want the user to be able to go to one of those, click to page 2 or refresh, and still be on that tab.

    Any help would be much appreciated!

  • #2
    Regular Coder
    Join Date
    Sep 2011
    Location
    Sweden
    Posts
    154
    Thanks
    1
    Thanked 22 Times in 22 Posts
    You can do this by setting and reading a cookie and you can read about how to do that here (and copy the necessary functions):

    http://www.quirksmode.org/js/cookies.html

    However - in my opinion - it would be better to do it by listening to hash changes:
    1) Let a click on a tab trigger a hash change
    2) Listen to the hash change event and change content accordingly.

    This would let the user navigate the site with the back and forward buttons in his browser, thus changing between tabs.

    Hash changes are a bit tricky to listen to in a cross-browser-compliant way. But there are some nice libraries out there that does this trick. I haven't used any standalone ones in a while, but I have experience from several different JQuery plugins. The one I would recommend is:

    http://tkyk.github.com/jquery-histor...#documentation

  • #3
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I get the theory behind it using this link: http://www.quirksmode.org/js/cookies.html

    But I don't know how to implement it into those tabs... I'm not very good with javascript at all so implementing this into HTML/PHP is foreign to me.


  •  

    Tags for this Thread

    Posting Permissions

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