environment variable as part of a src path

Discussion in 'HTML' started by Glennn, Apr 5, 2006.

  1. Glennn

    Glennn Guest

    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
     
    Glennn, Apr 5, 2006
    #1
    1. Advertising

  2. Glennn

    Steven Guest

    On 5 Apr 2006 15:33:18 -0700, "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>


    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
     
    Steven, Apr 5, 2006
    #2
    1. Advertising

  3. Glennn

    Jim Higson Guest

    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
     
    Jim Higson, Apr 6, 2006
    #3
  4. Glennn

    Steven Guest

    On Thu, 06 Apr 2006 08:55:23 +1000, Steven <> wrote:

    >On 5 Apr 2006 15:33:18 -0700, "Glennn" <>
    >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
     
    Steven, Apr 6, 2006
    #4
  5. Glennn

    Glennn Guest

    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
     
    Glennn, Apr 6, 2006
    #5
  6. Glennn

    Jim Higson Guest

    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
     
    Jim Higson, Apr 6, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Richter

    <txt src= ...> equivalent of <img src= ...>

    Steve Richter, Feb 8, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    2,192
    Laurent Bugnion
    Feb 9, 2006
  2. Greg Johnson
    Replies:
    4
    Views:
    3,144
  3. Replies:
    1
    Views:
    1,676
    Alex Hunsley
    Mar 23, 2007
  4. Replies:
    5
    Views:
    702
  5. pheadxdll
    Replies:
    16
    Views:
    3,898
    Neredbojias
    Jun 6, 2007
Loading...

Share This Page