Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if an HTML file is online or local folder

Tags:

javascript

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.

like image 940
Sabaz Avatar asked Feb 24 '15 19:02

Sabaz


People also ask

How do I show the file path in HTML?

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.

How do I open a local folder in HTML?

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.

How do I link to a local file in HTML?

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.

How do I copy an image path in HTML?

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.


1 Answers

window.location.protocol

can give you whether the file is local ("file:") or website ("http:")

Which is implemented by window.location

like image 140
puc Avatar answered Sep 18 '22 01:09

puc