![]() |
| ||
| Accessing environmetal variables Hi, I want to read an environmental variable using javascript.I have know idea of how to do that.Can anybody help me. |
| ||
| Re: Accessing environmetal variables Arumugams, Client-side or server-side environment? Airshow |
| ||
| Re: Accessing environmetal variables Quote:
|
| ||
| Re: Accessing environmetal variables Arumugams, Two categories: Browser environment and Computer/OS environment. Browser environment I've not looked at browser sniffers for a while as they are generally out of fashion in favour of "object testing" for code branching and error protection (if(document.getElementById) .... and the like). If you really need a browser sniffer then there are many examples out there. This looks like a good one: http://www.webreference.com/tools/br...avascript.html It is a bit out of date (last reported update 10/09/2006 but does include IE7 detection) but at least attempts to spot Opera in masquerade mode. What you see on the page is the sniffer's output. View source to get the code. Computer/OS environment Browser sniffing will detect the OS/version but any deeper (eg. processor/motherboard/bios stuff) is outside my experience I'm afriad. I would guess at somewhere between very difficult and impossible. You have to remember that browsers are buttoned down for security/privicy. LiveConnect to Java? Anybody? Airshow |
| ||
| Re: Accessing environmetal variables If you're referring to environment variables you create in a script, then just declare them with var and you refer to them anywhere in a script. :D |
| ||
| Re: Accessing environmetal variables Quote:
Thanks.. |
| ||
| Re: Accessing environmetal variables Mmmm now I'm confused. Where and how would you create this environment variable fooand where do you want its value to be available? Airshow |
| ||
| Re: Accessing environmetal variables Quote:
|
| ||
| Re: Accessing environmetal variables 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.locationor self.locationor simply location), which represents the URL of the file currently displayed in the window. Window.locationis conveniently provided with a set of properties and methods as follows: Properties
location.hostnamehowever 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.locationshould get you started. Whereas this has little to do with my understanding of "environmental variables", I hope it helps. Airshow |
| All times are GMT -4. The time now is 5:59 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC