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

Paul Novitski paul at novitskisoftware.com
Wed Aug 18 11:45:53 CDT 2004


At 08:04 AM 8/18/2004, Hakan Magnusson (Backbase) wrote:
>When using external scripts, does anybody know of a way to get a reference 
>to the script tag that included the script?


Hakan,

IFF you knew the name of the external script, you could of course search 
the document's script elements looking for your script's name in each href 
attribute.  Unfortunately this would only work if the script hadn't been 
renamed, and since you're talking about your script being used by other web 
designers maybe that's no kind of solution at all.

         - getElementsByTagName("SCRIPT")
         - search each array member for /external.js^/
         - if found, expose all script element attributes

Further idea: most of the scripts we write wait to execute until 
window.onload occurs.  If your external script started executing as soon as 
it was read & incorporated by the browser, presumably the incomplete 
document would extend only as far as the script tag itself.  If that were 
the case, could your external script examine the last element in the 
partial document to find its own external script tag?

Paul


At 08:04 AM 8/18/2004, Hakan Magnusson (Backbase) wrote:
>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
>_______________________________________________
>Javascript mailing list
>Javascript at LaTech.edu
>https://lists.LaTech.edu/mailman/listinfo/javascript





More information about the Javascript mailing list