2

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.

Marco Demaio
  • 33,578
  • 33
  • 128
  • 159
buggy1985
  • 919
  • 8
  • 24

2 Answers2

1

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.

Community
  • 1
  • 1
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
0

Another answer to same question:

What is my script src URL?

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.

Community
  • 1
  • 1
Marco Demaio
  • 33,578
  • 33
  • 128
  • 159