Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 535
prakash Avatar asked Mar 21 '26 17:03

prakash


1 Answers

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?

like image 97
Sam Deering Avatar answered Mar 23 '26 07:03

Sam Deering



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!