Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Jquery Cookie

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #31727
    yomoore
    Member

    Hi all,

    I need to set a cookie using jquery (I think jquery is the simplest and I like simple:))
    I have this:

    $("#close").click(function(){
    $("#block").fadeOut(200);
    });

    $("#open").click(function(){
    $("#block").fadeIn(200);
    });

    The code hides and shows a (div) block of content. I need a cookie so that a visitor is not presented with the default style every time one visits my website.

    Thanks

    #58884
    soap
    Participant
    #58886
    yomoore
    Member

    Hi soap,

    When I was googling the anwser the links you give me where the first I encountered. This was two days a go and I still don’t understand…

    #58892

    Using the jQuery cookie plugin – you would need to do the following (in order):

    1. Check to see if the user has your cookie already
    2. Set a cookie with the user

    To set the cookie, it would look like:

    setCookie(name, value);

    To see if the user already has the cookie – you would do:


    if($.cookie(name))
    {
    // Cookie already set
    // Do something
    }
    else
    {
    // Cookie not set - so set it
    setCookie(name, value);
    }
    #58866
    yomoore
    Member

    Hi,

    Thank you both but I just used this:
    http://www.vagrantradio.com/2009/10/getting-and-setting-cookies-with-jquery.html

    I modifed to my own script and it all works fine now. Thanks again anyway.

    #58859
    soap
    Participant

    Good work

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.