tags:

views:

22

answers:

1

How to create cookie, which will work on all pages over choosen site?

Using cookie plugin.

Code must add cookie "movie_check" with value "no", which can be used over all pages on site "www.site.com" (were script is implemented). Expires after 365 days.

Tryed this (doesnt work):

$.cookie("movie_check", "no", {expires: 365, domain: 'www.site.com'});

Thanks.

+1  A: 

Try:

 var date = new Date();
 date.setTime(date.getTime() + (3 * 24 * 60 * 60 * 1000));
$.cookie('movie_check', 'no', { path: '/', expires: date });

Your code sets an expiration date in the past.

Aaron Harun
what value gives date variable?
Happy
don't we need to add "domain" value ?
Happy
Date gives it a time 3 days into the future. Domain is automatically assumed to be the domain you are setting the cookie on.
Aaron Harun
If you pass a Number, it [means](http://plugins.jquery.com/files/jquery.cookie.js.txt) number of days in the future. So the original expires should be fine.
Matthew Flaschen
@Matthew Flaschen You're right.
Aaron Harun