I'm still not sure I fully understand but maybe this will help.
In client-side Javscript, all expressions are evaluated in the context of the current Window object, which provides the global namespace, not only for all your code but also for many top-level methods, variables and objects.
One such object is "location", (which can be referred to as either
window.location or
self.location or simply
location ), which represents the URL of the file currently displayed in the window.
Window.location is conveniently provided with a set of properties and methods as follows:
Properties- location.href : The whole URL
- location.protocol : eg, http or ftp
- location.hostname : eg. www.daniweb.com (aka the "domain")
- location.port : the host's port on which the document was/will be served. Optional; defaulting to port 80 if not specified.
- location.host : Equivalent to
location.hostname + ':' + location.port .
- location.pathname : the path, relative to the host's service root, to the served document.
- location.search : aka the "query string"; an optional string of name=value pairs, separated from the pathname by a "?" and from each other by "&".
- location.hash : an optional string representing a named anchor within the served document, separated from the pathname by a "#".
Methods- location.reload([force]) : reloads the current page. Optional boolean force instructs the server to reserve the page even if it has not been modified.
- location.replace(url) : Causes the document specified by url to be displayed, without making a new entry in the
window.history object. Use window.location.href to make a new entry in window.history .
I think what you are asking for is
location.hostname however in most circumstances, you don't need to use it.
The reason for this is that browsers are very good at doing the hard work for you. By default, if you specify a "relative" url, (ie one that omits the protocol and host) then your browser (and everybody else's) assumes these fragments to be the same as those of window.location (ie. those of the current document).
Hence in both HTML and Javascript you can work with relative rather than "absolute" urls (those that typically start with
http://). This means that files containing urls within the same site can be developed on a local computer then deployed to a live server without modification.
Of course, there are circumstances under which you may need to do something more complex, for example building a complete url from the ground up. I am due to publish a "code snippet" on this subject soon. Meanwhile the above explanation of
window.location should get you started.
Whereas this has little to do with my understanding of "environmental variables", I hope it helps.
Airshow