1

Possible Duplicate:
How to set/unset cookie with jQuery?

So I have this extremely simple jQuery function... My question is, how do I add a cookie when the DIV is hidden (i.e. faded out)? I want the cookie to be active until browser or window close.

In short, when a "visitor" clicks a specified X on a DIV (i.e. class .updateCloseBTN), it will hide the DIV. But if the user refreshes or revisits the page, the DIV will be shown again. If the user closes the DIV via the function below, it should not be loaded again, regardless if the user refreshes or revisits the page. However, it the user closes the browser window or browser itself and return the site, it will appear...

// Update Prompt: Hide on 'X' click 
$('.updateCloseBTN').click(function () {
    $('.upgradeWrap').fadeOut(400);
});
2
  • EDITED original post @VIDesignz Commented Nov 10, 2012 at 2:14
  • You'll need a plugin like this :) github.com/carhartl/jquery-cookie Commented Nov 10, 2012 at 2:21

1 Answer 1

4

First, You'll need a plugin like this :) https://github.com/carhartl/jquery-cookie

Once you get the plugin...

Create your cookie function

function setsomecookie(){
     $.cookie('the_cookie', 'the_value', { expires: 365 });
}

Use a callback for the fadeOut() animation.

$('.updateCloseBTN').click(function () {
    $('.upgradeWrap').fadeOut(400, setsomecookie);
});

This will run the 'setsomecookie' function after the fadeOut() is complete :)

Sign up to request clarification or add additional context in comments.

7 Comments

So what do I put in // Stuff, stuff & more stuff?
Problem is I'm not too sure how to create the cookie. That's where I'm stuck. Function arrangement I can do. :)
@MikeBarwick You'll need a plugin like this :) github.com/carhartl/jquery-cookie
@MikeBarwick Check this post, it will help you once you get the plugin :) stackoverflow.com/questions/1458724/…
Cheers man! Put your comments as an answer and I'll "check" ya ;)
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.