简体   繁体   English

如何提取JavaScript内容

[英]How to extract javascript contents

As we extract html contents using 当我们使用提取HTML内容时

alert(document.all[0].innerHTML);   

how can i extract javascript contents. 我如何提取JavaScript内容。

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. 您可以使用Ajax来获取脚本的内容-添加脚本标签后它们不会自动暴露给API-只能执行。 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. 但是,如果您打算稍后再执行代码,则可以使用eval()来执行此操作,但请记住,如果代码是全部或部分从不受信任的来源获得的,则这可能会给您的站点造成安全问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM