Search code examples
javascripthtmlmodified-date

Show File Modified Date With HTML File Running Off Network Drive - No Server


I have an html page running off a Windows network drive (no web server). The page has hyperlinks to other network files. Is there any way for me to return the last modified date of the files that the hyperlinks are pointing to and display them on the page? This is as web page running off a network drive without a web server? I am open to all and any out-of-the-box suggestions.

I thought maybe I could use a JavaScript fetch command but was not able to make it work. Is that due to JavaScript limitations accessing the Windows files?


Solution

  • Acessing HTML files from a file:// protocol page

    It is no longer possible to read HTML files from JavaScript in pages loaded with the file:// protocol. This is due to a tightening of security measures taken to disable access to HTML files, even in the same directory, in order to stop malware reading files that don't belong to them by guessing names that might exist because they have been generated by commonly used software. IIRC the use case was a demonstration of accessing email or message files named using a pattern, deduced as being possible before it appeared as malware in the wild.

    In consequence of measures taken, while HTML files using the file:// protocol can continue to access script, image and css files, attempts to access HTML files are essentially treated as cross domain - you can still load them in an iframe, but the window and document objects of the loaded page are no longer accessible to the opening page. Similarly if you open another page in a tab or new window, you won't be able to access contents of the window opened.

    You would need to create a server - either to serve pages, or possibly to just look up network file meta data and return results to HTTP requests received.

    TL;DR

    In modern browsers every URL of a page loaded with the file:// protocol is treated as a unique domain and can't directly access the content of other HTML pages stored locally or on a networked file system.


    Showing Users a directory listing with modified dates.

    You can, however, show users a directory listing of files (without the use of a server) by opening a page using the path of the directory turned into a file:// protocol. Typically the most common concern would be to escape spaces by replacing them with character sequence "%20"

    For example (not using a network) copy and paste any of these Windows URLs into the browser address bar and visit:

     file:///C:
     file:///C:/users
     file:///C:/Program%20Files
    

    Warning

    Showing file directory listings in the browser provides users with the ability to browse the file system in the browser window as a convenience. Typically users could always open the same directory path in Windows Explorer for the same purpose.