Sabaz
Sabaz

Reputation: 5282

Check if an HTML file is online or local folder

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.

Upvotes: 7

Views: 1672

Answers (1)

puc
puc

Reputation: 493

window.location.protocol

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

Which is implemented by window.location

Upvotes: 8

Related Questions