JavaScript: Loaded from web server or local computer?

Using JavaScript, how can I detect if a page was loaded from a web server or from a folder on a person's computer?

if( served_from_web_server ) alert('This page was loaded from a web server.');
else alert('This page was loaded locally');

Open in new window

LVL 16
hankknightAsked:
Who is Participating?
 
leakim971Connect With a Mentor PluritechnicianCommented:


if( location.href.indexOf("http") == 0 ) alert('This page was loaded from a web server.');
else alert('This page was loaded locally');
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.