©ilj@flowsim.se JavaScript code samples 11 JavaScript lastModified >>> this example in Swedish >>> this example in French This script displays the last modification date on the page. If the server does not supply this last modified date, the date displayed will be January 1, 1970. More further down about how to avoid this. <SCRIPT LANGUAGE = "JavaScript" TYPE="text/javascript"> <!-- document.write("Last modified " + document.lastModified) //--> </SCRIPT> displays the modification date of the page like this: Anything within quotation marks will be written as is on the page; you can easily replace the text "Last modified " by something else. Netscape och MIE 3- displays the last modified date as local; MIE 4 display it in GMT (Greenwich Mean Time). The format varies from one browser to another; this is for instance what it looks like in my
Here is a script that checks the date string before writing it on the page. Put it within SCRIPT tags (see MINIMANUAL 1 basics) and on the spot where you want the date to be displayed. var datumet = document.lastModified var datumnum = Date.parse(datumet) if(isNaN(datumnum)) { document.writeln("Last modified: " +datumet) //incomprehensible text string //just write it } else { if(datumnum == 0) { document.writeln("Last modified: unknown date") //no date received from server //if no code, 1970 would be displayed } else { //this is where you could put //code that rewrites the date //the way you want it document.writeln("Last modified: " + datumet) } } OTHER JAVASCRiPT EXAMPLES How to use javascript to choose what image to show by selecting it in an option list How to use javascript to switch images How to use javascript to switch images onmouseover JavaScript getDay() and document.write JavaScript date JavaScript timer How to use javascript to switch images onmouseover JavaScript timer JavaScript onmouseover JavaScript lastModified JavaScript/ text in text area JavaScript/ text in text area how to open new windows in JavaScript JavaScript clock JavaScript confirm JavaScript alert JavaScript prompt JavaScript onmouseover JavaScript onmouseover2 JavaScript animation JavaScript animation 2 Page by ilj@flowsim.se Last modified: December 4, 1997 This page should be part of a frames system at: http://www.flowsim.se JAVASCRiPT |