tags:

views:

52

answers:

1

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.

+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
Add an 'https:' case as well, and you'll be good to go.
Blackcoat