Storing a Last-Modified Date in a Cookie

Storing a Last-Modified Date in a Cookie

On informational Web sites, it is often handy to be able to show certain kinds of information only once, and then keep it hidden until it is updated. That way, users don’t have to look at the same message every time they come to the site. You can do this by setting a cookie with a version number and an expiration date. Cookies can be set in a variety of ways; one of the easiest is with JavaScript. To set a cookie that records the date a document was modified on, use the following code:


This code will store the last modified date in a cookie on the user’s machine, and you can refer to it as needed.


Share the Post: