views:

81

answers:

2

Hi,

In a javascript file (e.g. script.js) I need a variable that contains the absolute path to this file.

How can I do this dynamically?

Thanks.

+1  A: 

The answer to this question (genius, didn't know this was possible at all!) should yield the full URL to the file. This will work only when the script is included traditionally using a script tag, though.

Pekka
A: 

Another answer to same question:

http://stackoverflow.com/questions/984510/what-is-my-script-src-url/984656#984656

in above link they suggest to use also

scripts[scripts.length-1].getAttribute('src', -1)

I don't know why, but you might better investigate it a bit.

Marco Demajo