Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 865
  • Last Modified:

get environment variable in javascript web code

Hello,

does anyone know how to read an environment variable into a javascript running in a html page?

I would like to take appropriate action in the web page based on a particular environment variable....

thx,
Shaun
0
sbradley2002
Asked:
sbradley2002
  • 3
  • 2
1 Solution
 
[ fanpages ]IT Services ConsultantCommented:
Hi sbradley2002,

Local (workstation) environment variable, or one defined on the (Windows?) web server?

BFN,

fp.
0
 
sbradley2002Author Commented:
fanpages,

sorry didn't say,
I want it to read the variable from the client machine.
I should say that this web page is only being run as a web desktop on windows xp pro machines in my organisation, not actually being published anywhere

thx,
0
 
[ fanpages ]IT Services ConsultantCommented:
Hi,

I'm fairly certain that you cannot do this directly in HTML/Javascript alone.

You would need a scripting language such as Perl, CGI, PHP, VBScript etc on your client machine, or a Java applet.

Could you not use cookies instead?  And during installation of the client machines set the cookies to the initial values as defined in your DOS environment variables?

Or, maybe you could invoke the .htm(l) page with query parameters (?path=<...>&comspec=<...>) set by an external process (e.g. a Visual Basic .exe) that could read the environment variables in advance.

Sorry...

BFN,

fp.
0
 
sbradley2002Author Commented:
whatever works....
Would u know how to set up these cookies - or where I can find this info?
Can they be setup each time a user logs in on the machine?
0
 
[ fanpages ]IT Services ConsultantCommented:
The cookies would need to be set by a server-based process, that yes, could be invoked during log-on to the machine (if the machines are connected to a central server).

The server process would be called, query the environment variables of the connected workstation (maybe just a simply "set" command to a temporary file that is read on the server and cookie creation directly based on the contents of the file), and return to the log-in procedure.

Your client-side javascript should then query the cookies & act accordingly.

I don't know of any URLs off-hand.

Maybe just "google" for them?

BFN,

fp.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now