environment variable as part of a src path

G

Glennn

How would I reference an environment variable as part of the path to a
javascript file?

I've tried many variations similar to these in my head section, but so
far no success.

<script language="JavaScript" src="%MY_ENV_VAR%\bin\myScript.js"
type="text/javascript"></script>

<script language="JavaScript" src="$(MY_ENV_VAR)\bin\myScript.js"
type="text/javascript"></script>

Thanks in advance!

Glenn
 
S

Steven

How would I reference an environment variable as part of the path to a
javascript file?

I've tried many variations similar to these in my head section, but so
far no success.

<script language="JavaScript" src="%MY_ENV_VAR%\bin\myScript.js"
type="text/javascript"></script>

It sounds like you are trying to get code that is running in someone
else's browser to access something that is internal to your server. I
don't think this is possible. Maybe you could generate the page using
PHP and get it to replace the variable before the page is sent.
 
J

Jim Higson

Glennn said:
How would I reference an environment variable as part of the path to a
javascript file?

I've tried many variations similar to these in my head section, but so
far no success.

<script language="JavaScript" src="%MY_ENV_VAR%\bin\myScript.js"
type="text/javascript"></script>

<script language="JavaScript" src="$(MY_ENV_VAR)\bin\myScript.js"
type="text/javascript"></script>

That depends - is the env var set on your server or on the client's
computer?

If the former, most scripting languages can do that, but the syntax depends
on which one you use.

If the later, you can't.
 
S

Steven

It sounds like you are trying to get code that is running in someone
else's browser to access something that is internal to your server. I
don't think this is possible. Maybe you could generate the page using
PHP and get it to replace the variable before the page is sent.

My thinking here is flawed. I thought the browser would have to resolve
the %MY_ENV_VAR%. I don't think it can but it could send a request with
the variable in the URL and hope the server would resolve it. But I
still don't think it would work.

Could you just put the .js file in a special directory and include the
directory name in the URL ?
 
G

Glennn

Hi All,
Thanks for the responses!

Actually this is not running with a server. It's part of an application
with all code existing on one PC. It is expected that each PC running
this application would have this env var set with a path, but that path
will not necessarily be the same on each PC.

So, relative to the above replies, I suppose it would be considered as
a client env var. The question then is can a local env var be used
within an URL, when the source html and browser are all on the same PC.
If not, I suppose I may be adding more restrictions on where it finds
the .js file, but since in my situtation that .js is essentially part
of another application, this is where I was trying to make it
adaptable.

thanks again for any further suggestions.

Glenn
 
J

Jim Higson

Glennn said:
Hi All,
Thanks for the responses!

Actually this is not running with a server. It's part of an application
with all code existing on one PC. It is expected that each PC running
this application would have this env var set with a path, but that path
will not necessarily be the same on each PC.

The browser won't give environment variables to javascript. If it did,
there'd be some pretty serious privacy issues.
So, relative to the above replies, I suppose it would be considered as
a client env var. The question then is can a local env var be used
within an URL, when the source html and browser are all on the same PC.
If not, I suppose I may be adding more restrictions on where it finds
the .js file, but since in my situtation that .js is essentially part
of another application, this is where I was trying to make it
adaptable.

You'd probably have a happier time using a server like Apache. The kind of
thing you want (if I understand your problem properly) is very mature, well
documented and easy that way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top