I’d like to know if it is possible to write a bit of javascript in a web page to know
if the web-page is being hosted remotely or not.
Suppose I go and modify the hosts file
and I write
127.0.0.1 http://www.myexample.com
then I can run locally a webserver and display my test.html page
http://www.myexample.com/test.html
The question is: “can I figure out that I am running locally…?’
alternatively can I resolve the http://www.myexample.com into its address (but I think that’s more complicated)
No, this cannot be done with JavaScript on the browser side.
If you put example.com in your hosts file JavaScript doesn’t know if example.com is running locally or if it’s from another server for example.
Similar questions:
Determine IP# of domain from client browser
http://answers.yahoo.com/question/index?qid=20110606071036AAztRkF
http://javascript.about.com/library/blip.htm