0

I included external java script file in my page using usual script src = "myjs.js" - Can I assume that java script code should become part of DOM Now ? Can I Parse dom to get java script content in a var ?

I dont want to use HTMLHttpRequest and want to use in simple java script i.e. no dojo or jquery either. Can any one tell me is it possible if yes I will appreciate if you could help me figuring this out .

The core of the question is I want to spit out the java script on my page which is included in script tag under head tag - I want to do it without try to load the .js again i.e using HTMLHttpRequest.

Thanks in advance.

  • See [this question](http://stackoverflow.com/questions/4636843/is-external-javascript-source-available-to-scripting-context-inside-html-page) and [this question](http://stackoverflow.com/questions/4862955/can-javascript-access-source-code-of-a-script-src-element) – rsp Sep 18 '12 at 23:21

1 Answers1

0

No, the text of a script loaded from a file is not included in the document.

You can get the literal text (if the script shares the domain of the page) with the textContent of an AJAX call, which won't download it again, but will serve it from the cache.

You could include the script literally in the html, and use scriptelement.text, if you really have a dispise for XMLHttpRequest, which you may mean when you refer to HTMLHttpRequest.

kennebec
  • 102,654
  • 32
  • 106
  • 127
  • Thnx 4 reply n Sorry for my bad,I indeed meant XMLHttpRequest.Yes the problem is page dont share the same domain,infact it is a desktop application which has IE embeded in it my script file which i use to render the page is in the same directory where the page is served from the first Time. The problem is that application provide a copy feature of the page and when user click on the copy page is saved on another directory and my script is not reachable any more. I want the script back so can make use of it.How? there is complicated way but 1st thing that i need to get hold of script.thnx again – kabir ahmed Sep 18 '12 at 23:42