How to extract javascript contents
As we extract html contents using
alert(document.all开发者_开发问答[0].innerHTML);
how can i extract javascript contents.
Anyone who knows the answer, please help me Thanks in advance.
var firstScript = document.getElementsByTagName('script')[0];
alert(firstScript.innerHTML);
You can use Ajax to grab the script's contents--they are not automatically exposed to an API when a script tag is added--only executed. But if you are thinking of executing the code later on, you could use eval()
to do so, but bearing in mind that this can cause security problems for your site if the code is obtained in whole or part from untrusted sources.
精彩评论