Reputation: 3551
I have a JS file add in head
and would to get the lastModified
property. I tried this but doesn't work:
<head>
<script src="http://www.website.fake/code/quakes48h.js" type="text/javascript" id="utlime48ore"></script>
</head>
var last_mod48 = document.getElementById("ultime48ore").src.lastModified;
alert(last_mod48);
This returns error is null
. I hope you can help me.
Upvotes: 0
Views: 921
Reputation: 1079
Please read the documentation of the lastModified
property at MDN and W3Schools.
From W3Schools :
The lastModified property returns the date and time the current document was last modified.
From MDN :
Returns a string containing the date and time on which the current document was last modified.
What you are attempting to achieve with this property is not what it is meant for. Returning null
is normal because you are trying to check the lastModified of a non HTML DOM document
object which won't have it set.
If the intent is to get the last modification date of a file, it is best done on the server side in my opinion.
-- EDIT based on OPs mention of PHP --
If you are using PHP and wish to get the last modification time of a file local to the server, you could use the php filemtime($filename)
Filesystem function. Documentation may be found here
Example out of the documentation cited above :
<?php
// outputs e.g. somefile.txt was last modified: December 29 2002 22:16:23.
$filename = 'somefile.txt';
if (file_exists($filename)) {
echo "$filename was last modified: " . date ("F d Y H:i:s.", filemtime($filename));
}
?>
Upvotes: 1