Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript document.lastModified is returning current date and time

I'm using the standard document.lastModified Javascript property to output the supposed last modified date of the page, but it's outputting the actual current date and time. Any clue as to why it'd behave this way as opposed to outputting the actual last modified property of the page? This happens both locally (on my machine) as well as the published page on the delivery server.

like image 762
michael t Avatar asked Dec 18 '13 18:12

michael t


People also ask

Which property returns the date and time the document was last modified?

The lastModified property returns the date and time the document was last modified.

How do I use lastModified alert document?

javascript:alert(document.lastModified)A JavaScript alert window will pop open displaying the last date and time the page was modified. For users of the Chrome browser and some others, if you cut-and-paste the command into the address bar, be aware that the "javascript:" part is removed.

What does document lastModified contain?

lastModified is a read-only string property that contains the date and time at which document was most recently modified. This data is derived from HTTP header data sent by the web server. The web server generally obtains the last-modified date by examining the modification date of the file itself.

How to display last Modified date in JavaScript?

Javascript has provided a command called document. lastModified to get the instance when the document is last modified. This command will provide the exact date and time of modification.


1 Answers

document.lastModified I imagine is based on the HTTP Response Header field Last-Modified (RFC2822). Last-Modified is usually used in conjunction with the Request header field If-Modified-Since for caching purposes.

Like other header fields, it's server implementation specific as to what value is returned. The server software replying to your HTTP Request might or might not return the Last-Modified header field in the HTTP Response.

In the pages you are running this on, the server simply returns the current date. Same is true for this page.

However execute document.lastModified (in Dev Tools) on say https://developer.mozilla.org/en-US/docs/Web/API/document.lastModified, you'll get 11/13/2013 09:13:29

Using firebug in Firefox or Chrome Dev Tools in Chrome, you can see inspect HTTP traffic data in the Network tab.

like image 161
cbayram Avatar answered Nov 15 '22 01:11

cbayram