Sunday, November 8, 2009

document.lastModified in Google Chrome

It's fairly common to put something like document.write(document.lastModified); on a web page to display the date and time the document was last updated. This works fine in IE and in FireFox and seems like straight forward cross browser compatible and is kosher according to "JavaScript: The Definitive Guide, 5th ed."

Chrome doesn't like it. Now, for cross browser compatibility, you've gotta use
document.write(Date().toLocaleString(document.lastModified));


I'm not sure what's going on here. The Chrome JavaScript console shows document.lastModified as undefined. Maybe it's a WebKit thing. I'll have to see what Safari does.

Alright everyone... update your scripts!