[Javascript] Callback to script-tag from included script?
Roger Roelofs
rer at datacompusa.com
Wed Aug 18 11:46:02 CDT 2004
Hakan,
On Aug 18, 2004, at 12:12 PM, Hakan Magnusson (Backbase) wrote:
> Hi Roger,
>
> Thanks for the input, but document.location is no good. Because this
> script file can be included from anywhere in the site structure, it
> must be able to reference to its "own" location.
>
> This also has to be unique for every HTML-file that includes the file,
> so fixing on a global variable for the (absolute) path, like sMyPath =
> '/blah/js/external.js', is no good either.
>
> If the page is in 'blah/' I need to have 'js/external.js' as the data,
> and if the page is in 'blah/bluh/' I need to have '../js/external.js'
> as the data.
>
> Wicked, eh? :)
I don't have a copy of IE/win handy to test, but this works the same in
Mozilla browsers, and in Safari.
function getRef2Myself() {
var aScripts = document.getElementsByTagName("script");
for ( var i = 0; i < aScripts.length; i++ ) {
alert( i + ":" +aScripts[i].getAttribute("src"));
// returns text of the attribute
alert( i + ":" +aScripts[i].src);
// returns full url that the text resolves to
}
}
Roger
-------------------------------------------------------
Roger Roelofs web www.datacompusa.com
Datacomp Appraisal Services web www.mhvillage.com
3215 Eaglecrest Drive, NE Email rer at datacompusa.com
Grand Rapids, MI 49525-4593
More information about the Javascript
mailing list