Getting content of – jfriend00 Apr 22 '13 at 05:03

3 Answers3

5

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

TGH
  • 38,769
  • 12
  • 102
  • 135
0

You can fetch the contents of a script file with ajax if it comes 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.

jfriend00
  • 683,504
  • 96
  • 985
  • 979
0

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.

slebetman
  • 109,858
  • 19
  • 140
  • 171