Is it possible to access the file creation time of an <img> src in javascript?

Viewed 13155

Given the following example

<img id="my_img" src="images/current.png" />

<script language="javascript">
var i = document.getElementById('my_img');
var filetime = i.is_there_any_method_for_this(); // ?????
i.title = 'image created: ' + filetime; // don't care about formating now
</script>

I'd like to ask if is_there_any_method_for_this(); exists or if it's at all possible to access the file creation (or modification) time of the displayed image.

7 Answers

How about going with $.ajax and limit the request to only the HEAD...

var i = document.getElementById('my_img');
var xhr = $.ajax( {
    type: 'HEAD',
    url: i.src,
    success: function(msg) {
        var filetime = xhr.getResponseHeader('Last-Modified');
        i.title = 'image created: ' + filetime;
    }
});
Related