i'm loocking for a javascript code (if it's possible) to check if an HTML file has been launched/read from a remote host or from a local folder of pc.
..let me explain better with an example:
i've an html file in C:/folder/file.html if i launch it by double-clicking, a js script print "read from local" on the document.
Now, if i host it on a my website, like www.mydomain.org/file.html and open that page, the js script print "read from online"
This would be greatly helpful, thank you for now.
To insert a file in a web page its source must be known. For example, the syntax (<img src=” ” alt=” “>) is used to insert an image file, where the path of the file is mentioned in the source (src). File paths are of two types: Absolute File Paths.
HTML can be used to open a folder from our local storage. In order to open a folder from our local storage, use 'HREF' attribute of HTML. In the HREF attribute, we specify the path of our folder.
You need to use the file:/// protocol (yes, that's three slashes) if you want to link to local files. These will never open the file in your local applications automatically. That's for security reasons which I'll cover in the last section. If it opens, it will only ever open in the browser.
Conclusion. In HTML, the <img> tag is used to add an image from the folder to the HTML document. The image path is specified by the src attribute of <img> tag. To specify the path, firstly write the folder name, then a backslash “/” and lastly, write the image name with its extension.
window.location.protocol
can give you whether the file is local ("file:") or website ("http:")
Which is implemented by window.location
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With