Pratik Bhatt
Pratik Bhatt

Reputation: 911

How to update cookie expiration time with JavaScript?

I want sliding time for expiration time of cookie. This can be done by getting cookie and again setting with new expiration time and deleting previous cookie. But , I want to know better way than this . I need some good solution.

Upvotes: 3

Views: 11925

Answers (1)

rink.attendant.6
rink.attendant.6

Reputation: 46208

By "sliding time" I'm assuming you want the cookie to renew itself whenever the visitor reloads the page. Just reset the cookie every time the page loads (i.e. every time the JavaScript code is executed).

https://developer.mozilla.org/en-US/docs/DOM/document.cookie

However if you're looking for something more long term with more capacity then I would recommend using localStorage:

https://developer.mozilla.org/en-US/docs/DOM/Storage#localStorage

Upvotes: 6

Related Questions