[Javascript] Callback to script-tag from included script?

Hakan Magnusson (Backbase) hakan at backbase.com
Wed Aug 18 10:04:25 CDT 2004


When using external scripts, does anybody know of a way to get a 
reference to the script tag that included the script?

-- Example, HTML:

<link type="text/css" rel="stylesheet" href="css/default.css" />
<script type="text/javascript" src="external.js"></script>

-- The file external.js:

// Should alert "css/default.css"
alert(tagSelf.previousSibling.getAttribute('href'));

--

I am not interested in solutions that involve setting variables or 
running scripts anywhere but inside external.js, the HTML must remain 
completely clean.

Also, it must be a reasonable solid way of doing it in both IE and Mozilla.

Regards,
H



More information about the Javascript mailing list