转储包含.js的内容 [英] Dumping content of included .js

查看:52
本文介绍了转储包含.js的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从.js文件转储源代码并将其保存到

字符串?类似于:


< head>

< script language =" JavaScript" src =" http://www.abc.com/test.js"

type =" text / javascript">< / script>

< ; script>

函数dumpScript(){

var scripts = document.getElementsByTagName(''SCRIPT'');

alert(脚本[ 0] .source);

}

< / script>

< / head>


< body>

< button onclick =" dumpScript()"> DUMP SCRIPT< / button>

< / body>


提前致谢!

Is it possible to dump the source code from a .js file and save it to a
string? Something like:

<head>
<script language="JavaScript" src="http://www.abc.com/test.js"
type="text/javascript"></script>
<script>
function dumpScript() {
var scripts = document.getElementsByTagName(''SCRIPT'');
alert(scripts[0].source);
}
</script>
</head>

<body>
<button onclick="dumpScript()">DUMP SCRIPT</button>
</body>

Thanks in advance!

推荐答案

nick于11/8/2006 6发表以下内容:下午39点:$ b​​ $ b
nick said the following on 11/8/2006 6:39 PM:

是否可以从.js文件转储源代码并将其保存到

字符串?类似于:
Is it possible to dump the source code from a .js file and save it to a
string? Something like:



不,你最接近的将是使用

XMLHTTPRequest对象(流行语中的AJAX)检索文件然后从文件中读取

responseText。


Opera9将让你读取脚本元素.text属性:


document.scripts [0] .text


-

兰迪

机会有利于预备心灵
comp.lang.javascript常见问题 - http://jibbering.com/faq

Javascript最佳实践 - http://www.JavascriptToolbox。 com / bestpractices /

No, the closest you could come would be to retrieve the file using an
XMLHTTPRequest Object (AJAX in buzz words) and then read the
responseText from the file.

Opera9 will let you read the script elements .text property:

document.scripts[0].text

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/




Randy Webb写道:

Randy Webb wrote:

nick在11/8/2006 6:39 PM说了以下内容:
nick said the following on 11/8/2006 6:39 PM:

是否可以从a转储源代码。 js文件并将其保存为

字符串?类似于:
Is it possible to dump the source code from a .js file and save it to a
string? Something like:



不,你最接近的将是使用

XMLHTTPRequest对象(流行语中的AJAX)检索文件然后从文件中读取

responseText。


Opera9将让你读取脚本元素.text属性:


document.scripts [0] .text


No, the closest you could come would be to retrieve the file using an
XMLHTTPRequest Object (AJAX in buzz words) and then read the
responseText from the file.

Opera9 will let you read the script elements .text property:

document.scripts[0].text



Firefox有ViewSourceWith扩展(以及其他) - 可能更少

方便但提供更多功能:-)

< URL: https://addons.mozilla.org/firefox/394/ >


-

Rob

Firefox has the ViewSourceWith extension (among others) - maybe less
convenient but provides a few more features :-)

<URL: https://addons.mozilla.org/firefox/394/ >

--
Rob


Firefox有ViewSourceWith扩展(以及其他) - 可能更少
Firefox has the ViewSourceWith extension (among others) - maybe less

方便但提供了更多功能:-)

< URL: https://addons.mozilla.org/firefox/394/ >


-

Rob
convenient but provides a few more features :-)

<URL: https://addons.mozilla.org/firefox/394/ >

--
Rob



这不是一个错误。你加载的脚本没有运行的原因是

没有完全加载。

1.你可以在脚本块之前加载脚本主要块;

2.使用来自xml文件的XMLHttp加载脚本,而不是使用全局函数

eval()来运行它。

3。设置一个setTimeout()来等待所有完全加载的代码。

It''s not a bug. The reason of that script you loaded has''nt run is it
hasn''t loaded completely.
1. you can load the script in a script chunk before your main chunk;
2. use XMLHttp load script from xml files, than use global function
eval() to run it.
3. set a setTimeout() to wait for all the code loaded completely.


这篇关于转储包含.js的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆