Eureka ! I found how to obtain a date with Opera ...
To avoid that the browser tries to read the image lastModified in the cache, you have only to call
Code:
dt=LastModUsingHeader('upload.jpg?'+Math.random());
// or to modify the function
function LastModUsingHeader(U) {
var X = !window.XMLHttpRequest ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest;
X.open('GET', U+'?'+Math.random(), false);
try{ X.send();}catch(y){}
var dt=X.getResponseHeader('Last-Modified');
return new Date(dt).toLocaletring();
}
// to write
<p>Image uploaded: <i id="ImageDate"></i></p>
This could be applied too to the image src...
It would be better to have a DOCTYPE for the page (See W3C) and to display meta tags to control the cache (See this page) to choose a Meta tag...
Otherwise the users could have difficulties to update the page...
11-20-2011, 04:47 PM
gangerolv
Thanks to all!
This is the code I'm using and it seems to work for Opera, Firefox and IE. The date/time stamp of a file shows up correctly at local time:
Code:
<p>Image uploaded: <i id="getImageDate"></i></p>
<script type="text/javascript">
function LastModUsingHeader(sFile) {
var X = !window.XMLHttpRequest ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest;
X.open('GET', sFile, false);
try{ X.send();}
catch(y){}
var dtImage=new Date();
dtImage = X.getResponseHeader('Last-Modified');
return new Date(dtImage).toLocaleString();
}