Several properties of the Document object provide information about the document as a whole. For example, the following code shows how you can use the lastModified, title, and URL properties to include an automatic timestamp within a document. This feature allows users to judge how up-to-date (or out-of-date) a document is, and it can also be useful information when a document is printed.
<hr><font size="1"> Document: <i><script>document.write(document.title);</script></i><br> URL: <i><script>document.write(document.URL);</script></i><br> Last Update: <i><script>document.write(document.lastModified);</script></i> </font>
<script> // If linked from somewhere offsite, go to home page first if (document.referrer == "" || document.referrer.indexOf("mysite.com") == -1) window.location = "http://home.mysite.com"; </script>
Don't consider this trick to be any kind of serious security measure, of course. One obvious flaw is that it doesn't work for browsers that don't support JavaScript or for users who have disabled JavaScript.
Copyright © 2003 O'Reilly & Associates. All rights reserved.