[英]Load JavaScript file source code as plain text and access its content using JavaScript
Is it possible to download a script file using the script tag like this 是否可以像这样使用script标签下载脚本文件
<script src="http://webserver.com/script.js"></script>
and then be able to read the loaded file content with JavaScript, like this for example: 然后能够使用JavaScript读取加载的文件内容,例如:
var scriptContent = window.scripts[0].content;
What i came to notice is that the loaded JavaScript file contents is not accessible by other JavaScript files or am i wrong ? 我注意到的是,其他JavaScript文件无法访问已加载的JavaScript文件内容,或者我错了吗?
No, it is not possible to do that. 不,这是不可能的。
The source code of a script loaded via src
is not exposed via any API made available to JavaScript running in the page. 通过
src
加载的脚本的源代码不会通过该页面中运行的JavaScript可用的任何API公开。
You could read the value of src
and then fetch it using XMLHttpRequest
. 您可以读取
src
的值,然后使用XMLHttpRequest
进行获取。
The source code of specific functions may be available by calling toString()
on them. 通过调用特定函数的
toString()
可以获取特定函数的源代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.