Javascript document.lastModified is returning current date and time

前端 未结 2 490
执念已碎
执念已碎 2020-12-11 06:25

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 curren

相关标签:
2条回答
  • 2020-12-11 06:36

    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.

    0 讨论(0)
  • 2020-12-11 06:58

    Tested lastModified on a local file on my hard drive. Chrome returns current time/date and not when file was saved. Internet Explorer and Firefox return time/date file was saved. So this is a Chrome bug. Get page to check if Chrome from the userAgent and warn user or disable code.

    Blockquote

    if(navigator.userAgent.indexOf("Chrome/")>0){ alert("Chrome bug.\nPlease use a different browser.\nOne that works."); }

    Blockquote

    Other problems with lastModified. It returns a string and not a date object. So can't use date.getFullYear() The string is in the USA format and not the standard format of d/mm/yyyy

    0 讨论(0)
提交回复
热议问题