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);
});
Community
  • 1
  • 1
Mike Barwick
  • 6,288
  • 6
  • 51
  • 76

1 Answers1

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

VIDesignz
  • 4,703
  • 3
  • 25
  • 37