Javascript document.lastModified is returning current date and time

前端 未结 2 492
执念已碎
执念已碎 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: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

提交回复
热议问题