I'm a newbie to javascript. How can I detect if my javascript is being run from a web site (http://) vs a local file.
views:
52answers:
1
+10
A:
switch(window.location.protocol) {
case 'http:':
case 'https:':
//remote file over http or https
break;
case 'file:':
//local file
break;
default:
//some other protocol
}
Jacob Relkin
2010-10-13 05:01:07
Add an 'https:' case as well, and you'll be good to go.
Blackcoat
2010-10-13 05:09:08