Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > environment variable as part of a src path

Reply
Thread Tools

environment variable as part of a src path

 
 
Glennn
Guest
Posts: n/a
 
      04-05-2006
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

 
Reply With Quote
 
 
 
 
Steven
Guest
Posts: n/a
 
      04-05-2006
On 5 Apr 2006 15:33:18 -0700, "Glennn" <(E-Mail Removed)>
wrote:

>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.

--
Steven
 
Reply With Quote
 
 
 
 
Jim Higson
Guest
Posts: n/a
 
      04-06-2006
Glennn wrote:

> 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.

--
Jim
 
Reply With Quote
 
Steven
Guest
Posts: n/a
 
      04-06-2006
On Thu, 06 Apr 2006 08:55:23 +1000, Steven <(E-Mail Removed)> wrote:

>On 5 Apr 2006 15:33:18 -0700, "Glennn" <(E-Mail Removed)>
>wrote:
>><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.


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 ?

--
Steven
 
Reply With Quote
 
Glennn
Guest
Posts: n/a
 
      04-06-2006
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

 
Reply With Quote
 
Jim Higson
Guest
Posts: n/a
 
      04-06-2006
Glennn wrote:

> 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.

> thanks again for any further suggestions.
>
> Glenn


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What does the SRC in <IMG SRC> stand for? pheadxdll HTML 16 06-06-2007 02:45 AM
Setting an environment variable from another environment variable marcwentink@hotmail.com Java 5 04-04-2007 10:39 PM
Convert Java Src to J2ME Src? macbrando@gmail.com Java 1 03-23-2007 01:29 PM
<txt src= ...> equivalent of <img src= ...> Steve Richter ASP .Net 3 02-09-2006 08:44 PM
src.jar (src.zip) missing on Mac OSX Java 1.4.1 installation? Greg Johnson Java 4 09-18-2003 07:21 AM



Advertisments