Accessing environmetal variables

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Apr 2009
Posts: 11
Reputation: Arumugams is an unknown quantity at this point 
Solved Threads: 0
Arumugams Arumugams is offline Offline
Newbie Poster

Accessing environmetal variables

 
0
  #1
May 25th, 2009
Hi,
I want to read an environmental variable using javascript.I have know idea of how to do that.Can anybody help me.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 857
Reputation: Airshow is on a distinguished road 
Solved Threads: 122
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark

Re: Accessing environmetal variables

 
0
  #2
May 25th, 2009
Arumugams,

Client-side or server-side environment?

Airshow
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 11
Reputation: Arumugams is an unknown quantity at this point 
Solved Threads: 0
Arumugams Arumugams is offline Offline
Newbie Poster

Re: Accessing environmetal variables

 
0
  #3
May 25th, 2009
Originally Posted by Airshow View Post
Arumugams,

Client-side or server-side environment?

Airshow
Its in client side.
Last edited by Arumugams; May 25th, 2009 at 8:52 am.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 857
Reputation: Airshow is on a distinguished road 
Solved Threads: 122
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark

Re: Accessing environmetal variables

 
0
  #4
May 25th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 119
Reputation: JugglerDrummer is an unknown quantity at this point 
Solved Threads: 15
JugglerDrummer's Avatar
JugglerDrummer JugglerDrummer is offline Offline
Junior Poster

Re: Accessing environmetal variables

 
0
  #5
May 25th, 2009
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.
92% of all statistics are made up on the spot.

If you found a post helpful, please click the "give XXX reputation" link, to show your appreciation to those who helped you. Thanks! :D
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 11
Reputation: Arumugams is an unknown quantity at this point 
Solved Threads: 0
Arumugams Arumugams is offline Offline
Newbie Poster

Re: Accessing environmetal variables

 
0
  #6
May 25th, 2009
Originally Posted by JugglerDrummer View Post
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.
I dont create the variable in the script.Example if some environment variable like foo is created manually.I need the value of the variable.
Thanks..
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 857
Reputation: Airshow is on a distinguished road 
Solved Threads: 122
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark

Re: Accessing environmetal variables

 
0
  #7
May 26th, 2009
Mmmm now I'm confused.

Where and how would you create this environment variable foo and where do you want its value to be available?

Airshow
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 11
Reputation: Arumugams is an unknown quantity at this point 
Solved Threads: 0
Arumugams Arumugams is offline Offline
Newbie Poster

Re: Accessing environmetal variables

 
0
  #8
May 26th, 2009
Originally Posted by Airshow View Post
Mmmm now I'm confused.

Where and how would you create this environment variable foo and where do you want its value to be available?

Airshow
Sorry to confuse you.I have written one code for sending data to the server.The server address may vary depending on where the server is hosted.Instead of changing the address of server in the code ,I want to read the server address from the environment variable which is created manually.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 857
Reputation: Airshow is on a distinguished road 
Solved Threads: 122
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark

Re: Accessing environmetal variables

 
2
  #9
May 26th, 2009
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
Last edited by Airshow; May 26th, 2009 at 2:29 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC