Javascript Tutorial -- Adding a "Last Modified" Timestamp to Your HTML Documents



Have you ever seen a web page that contained a footer with a time stamp for the date/time of the last modification to the HTML document? There are a lot of ways to include this data in your web pages -- Server-Side Includes (SSI), CGI scripts, and...you guessed it: Javascript.

Do you remember talking about the document object in Lesson 9? Well, the document object contains other methods and data besides the write method. One of the data elements you can obtain from the document object is the "lastModified" element, which contains the time and date the HTML document was last updated. It is trivial to poll this data element and use it in an HTML document:
        <script type="text/javascript">
          <!--
            document.write("last updated " + document.lastModified)
          //-->
        </script>
      
Here is how it looks in an HTML document.