admin管理员组文章数量:1335401
I am trying to get content of <script>
tag in html:
i can get <script>test</script>
content by using jquery $("script").html()
.
but how to get content of
<script src='something.js'></script>
?
I am trying to get content of <script>
tag in html:
i can get <script>test</script>
content by using jquery $("script").html()
.
but how to get content of
<script src='something.js'></script>
?
- 3 Possible duplicate of How can I get the content of the file specified as the 'src' of a <script> tag? and also possible dup of Can JavaScript access source code of a <script src=“”> element? – jfriend00 Commented Apr 22, 2013 at 5:03
3 Answers
Reset to default 5What about this.
$.get("/something.js",function(scriptContent){alert(scriptContent)});
It will pull the content through an ajax request
Alternatively, you can pull the content on the server and return it back to the client by making a request to a page that facilitates the loading of the JS file on the server. This is necessary if the js file is hosted under a different domain
You can fetch the contents of a script file with ajax if it es from the same domain as your page.
If you can explain what problem you're really trying to solve, we can likely give you better options.
You can get the content of javascript files (or any text file for that matter) using Ajax. Either use XMLHttpRequest
then read the responseText
or load it in an iframe.
Be warned that both methods are limited by the same origin policy.
本文标签: javascriptGetting content of ltscriptgt tagStack Overflow
版权声明:本文标题:javascript - Getting content of <script> tag - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742388657a2465547.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论