开发者

getting the path of a javascript file

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

H开发者_运维问答ow can I do this dynamically?

Thanks.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜