我在页面上包含一个脚本,如下所示。
<script src="https://domain/demo.js" type="text/html" id="google_script"></script>
加载 demo.js
后,我需要获取加载的 demo.js 的内容,而无需使用 ajax 调用它。如果可能以及如何实现,请分享您的想法。
最佳答案
遗憾的是没有。
使用纯 JavaScript,您无法在不执行其他 JavaScript 文件的情况下获取其内容。
可能的解决方案:
- Use PHP
- 将 JS 文件保存为文本文件,然后 load it to iframe并获取来源
- Get the source ,但是运行脚本
编辑: 使用 JavaScript,您无法获得完整的脚本,但功能如下:
var funcsourcecode = functionname.toString();
关于javascript - 获取页面上包含的外部脚本的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43818689/