Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

"Page last Updated" JavaScript

Opera Browser has wrong date



3:20 am on Jan 19, 2006 (gmt 0)

10+ Year Member

All the other browsers post the correct date. The Opera browser post the Last update as 07/31/1969. The script is below. How can this be corrected?
Thanks in Advance

<script language="Javascript">
document.write("The page that contains this example was last updated on: "+document.lastModified+"")

JAB Creations

12:09 am on Jan 20, 2006 (gmt 0)

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Hi SenMar,

Does the page with the error use any serverside scripting? If so then JavaScript will (correctly) send the time the file was rendered.

The solution is to use the serverside language you're using to achieve this instead, though I'm not sure what language that is.

Let me know what language and I'll try to help you out.



8:01 pm on Jan 20, 2006 (gmt 0)

10+ Year Member

The document.lastModified item is part of a group of which some of the items can be used for attacking the server. Some ISP's simply ban the entire group rather than blocking the individual bad items. When that is done, the document.lastModified is returned as a null value.

Internet Explorer takes the null value, uses it as-is in the "new Date()" function, and gets back the CURRENT date and time. This makes it appear that the page was updated just seconds ago. If you don't look too closely, this seems to be correct, and you're happy with what you see.

Netscape takes the null value, forces it to numeric, gets a zero at this point, uses that zero in the "new Date()" function, and gets back the first midnight of January 1st in 1970. It then applies the timezone offset value to give a proper answer based on the user's machine. For me, in the eastern USA, this displays as 7:00pm on December 31 of 1969.

WebTV functions similarly to Netscape, but does the timezone offset earlier in the procedure. This results in a negative value to the "new Date()" function and causes an error.

I've not checked Opera, but it seems to be following the Netscape pattern.


Featured Threads

Hot Threads This Week

Hot Threads This Month