Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to retrieve the last modified date of a file using Javascript?

I have a set of links on a web page that link to PDF forms and .doc forms. These files are not stored in a database, simply stored as they are, locally on the server. Is it possible to retrieve the last modified date of a PDF or DOC file using Javascript? I don't have any specific need to use Javascript, but it is preferable.

UPDATE: Now that I realize that Javascript can't access the filesystem, is there an alternative method?

like image 378
Riddari Avatar asked Feb 22 '10 19:02

Riddari


People also ask

What is date last modified?

The "Last Time Modified" date refers to the last time a document or media file was modified. This information is gathered from metadata within the document or from the website's servers. Last Time Modified date can be viewed under Documents in the Inventory module of Quality Assurance.

How do I find the last modified date of a file?

The lastModified() method of the File class returns the last modified time of the file/directory represented by the current File object. You can get the last modified time of a particular file using this method.

Which property of html5 file API returns the last modified time of the file?

The lastModified property returns the date and time the document was last modified.

How do I get the last modified date in HTML?

The DOM lastModified property in HTML is used to return the date and time of the current document that was last modified. This property is read-only. This property returns a string which contains the date and time when the document was last modified.


1 Answers

If it's on the same server as your calling function you can use XMLHttpRequest-

This example is not asynchronous, but you can make it so if you wish.

function fetchHeader(url, wch) {
    try {
        var req=new XMLHttpRequest();
        req.open("HEAD", url, false);
        req.send(null);
        if(req.status== 200){
            return req.getResponseHeader(wch);
        }
        else return false;
    } catch(er) {
        return er.message;
    }
}

alert(fetchHeader(location.href,'Last-Modified'));
like image 143
kennebec Avatar answered Sep 27 '22 18:09

kennebec