[thelist] Accessing "URL" variables in JavaScript

Steven Wood steve.wood at serviceengine.com
Thu Oct 12 17:28:00 CDT 2000


This is going to be tough to explain, but here goes.

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>

The ID variable will be unique to them.

I'm doing this because the code within myscript.js contains javascript that
outputs a link to a pop-up window that I don't want my clients modifying.  I
can't figure out how to reference the URL variable 'ID' within the src
attribute in the <script> tag.  I'm having trouble because it's not really
IN the URL, if you follow me!

In myscript.js, I have some javascript that searches the URL and returns the
value of the ID variable that was passed in it, but I need to know how to
reference the src attribute above... instead of referencing the actual page
URL.

Here is the code within myscript.js:

var query = location.search.substring(1);
var pos = query.indexOf('=');
var ID = query.substring(pos+1,query.length);

var link = "<a href=\"#\"
onclick=\"window.open(\'http://www.mywebsite.com/popuppage.cfm?ID=" + ID +
"\', \'PopupWindow\',
\'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes
,resizable=yes,copyhistory=no,width=400,height=500,screenX=150,screenY=100,l
eft=150,top=100\')\">Pop Up This Window!</a>";

document.write(link);

My problems lies with the line "location.search.substring(1);".  This, of
course, refers to the URL.  How can I, instead, refer to the URL within the
src attribute of my <script> tag?  Any clues?

Skadar





More information about the thelist mailing list