Search code snippets, questions, articles...

Set a cookie that never expires using Javascript

You can not set a cookie that never expires but you can use the highest value possible for the expiration date.
document.cookie = "cookie_name=cookie_val; expires=Fri, 31 Dec 9999 21:10:10 GMT";
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place.

In the above code snippet, we have used year 9999 for a cookie to expire.

Was this helpful?