Search code examples
javascriptmetadata

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?


Solution

  • Using the modern fetch method:

    var lastMod = null;
    fetch(xmlPath).then(r => {
        lastMod = r.headers.get('Last-Modified');
        return r.text();
    })