prakash
prakash

Reputation: 131

Regarding cookie

I am setting a session cookie in one page using

setCookie("cookietime","1000");

And resetting it to "" on going back to previous page

setCookie("cookietime","");

When I go back I am showing an alert after seeting the cookie to "". it is showing "" in alert. But in the next page it still shows "1000". Is the cookie page specific

Upvotes: 3

Views: 81

Answers (2)

pbojinov
pbojinov

Reputation: 927

Session cookies are temporary cookie files that will be removed when you close your browser.

Persistent cookies remain on your browser until it expires or until you erase them.

Neither are page specific.

Note that session cookies in Firefox will be restored after a browser restart when you use the session restore feature, which can cause some inconsistencies.

Upvotes: 0

Sam Deering
Sam Deering

Reputation: 368

Cookies are stored client side and are computer+browser specific not page specific! I guess you are using document.cookie which should persist through the session - they persist even when the page is refreshed. Using window.name will only persist through the same browser window but will clear on page refresh. HTML5 localStorage may be a suitable alternative.

Relates question: Persist javascript variables across pages?

Upvotes: 1

Related Questions