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>
?
What 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.