简体   繁体   English

获取 JavaScript 文件的 URL

[英]Get URL of JavaScript File

location.href gives me the URL of the page I'm on. location.href 为我提供了我所在页面的 URL。 The page contains this:该页面包含以下内容:

<script src="http://mydomain/myscript.js"></script> 

Inside of myscript.js is there a property that gives me the script URL ("http://mydomain/myscript.js")? myscript.js 内部是否有一个属性可以提供脚本 URL(“http://mydomain/myscript.js”)?

I don't know what you mean, but i think that you want to find the src of all scripts.我不知道你的意思,但我认为你想找到所有脚本的 src。 I found this to work:我发现这个工作:

 let array_of_src=[]
 document.querySelectorAll('script').forEach(function(element){array_of_src.push(element.src)})
 //do stuff with the array of all the srcs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM