[thelist] Accessing "URL" variables in JavaScript

Ben Henick persist1_pdx at yahoo.com
Sun Oct 15 01:25:50 CDT 2000


> I want my clients to drop this code into their websites:
> <script language='javascript'
>
src='http://www.myserver.com/myscript.js?ID=%24%29H%2D%28S%40%20%2E%B2'></sc
> ript>

[Rest of message clipped for clarity]

If I understand properly - and I'm not entirely sure that I do - you
want to pass a value to the script that's in fact external to the page
code.

First off, Netscape gives you no means by which you can make this work
properly - it knows how to work off of document.location, but in every
case document.location is going to be the page into which the script is
loaded.

IE's a bit more flexible, as you can retrieve the specific ID of the
tag that calls the script and work off of its SRC any way you please.

var WindowURL = document.all["script_id"].src.substring(x);

I suppose you may have to copy the entire SRC to a variable or string
first, and work from a substring of that object.  x in this case is the
zero-indexed value where the QUERY_STRING would start.

The difference between this technique and the one mentioned in your
message is not, near as I can tell, practically nil.

If you need more of a cross-platform solution, I would recommend this
instead:  just create a separate script block, between tags and have
the client insert THAT instead.

var SpecificURL = PopupURL + QUERY_STRING_specific_to_client;
newWindow = window.open(SpecificURL,"...","...");

The page specified by 'PopupURL' could then contain JavaScript to
present whatever you were hoping for in that particular case.

At least, that'd be my approach to the objective.  Comments and
brickbats are welcome.



=====
Ben Henick              |  "In the long run, men hit only
Web Author At-Large     |  what they aim at.  Therefore,
www.io.com/persist1/    |  though they should fail
persist1 at io.com         |  immediately, they had better aim
persist1_pdx at yahoo.com  |  high."  --Henry David Thoreau

__________________________________________________
Do You Yahoo!?
Yahoo! Messenger - Talk while you surf!  It's FREE.
http://im.yahoo.com/




More information about the thelist mailing list