lastModified as a comment


Is it possible to display the last modified date/time as a comment in HTML?



What do you mean by “comment”?

<!-- Do you mean this? -->

I’m sure you could… I don’t see what the point would be though. Javascript is only run clientside and if the client can’t see it, then why do it?

Yes, I mean like that.

It would be useful for my team to see when the page was last updated by just viewing the source.

Ah. Seems odd… but here you go:

window.onload = function() {
    document.body.innerHTML += '<!-- ' + document.lastModified + ' -->';	

I’ve never used the document.lastModified method before. The info on it is sparse… make sure it does what you want it to do. Seems like a very weird thing to be on the client-side.

I tried something similar to this, hoping to help with this question, but document.lastModified changed every time I loaded the page, always reflecting the current time.

I’m trying to figure out an AJaX way of doing it, but I’m not using IIS or Apache as a webserver (I’m running ColdFusion Servers built-in web server.)

    WriteOutput(GetFileInfo("c:\	emp\	est1.txt").lastmodified);

Thanks for the CF method. That will come in handy, I’m sure, in the future.

But I’m thinking of switching from CFs built-in Tomcat webserver to Apache (to reflect production environment). So there might be an AJaX way of getting “Last-Modified” response header.

Most hosting providers now block access the file dates so lastModified will almost always return the date and time it is run.

Bummer. So even if I did find/write a script to do so, it’s already thwarted by most ISPs.:smash: