Java Script 对象存储在磁盘上的什么位置?
我是 Java 脚本新手。此 HTML 和 Java 脚本代码使用 Google Transliteration API 将英语单词音译为孟加拉语。我在浏览器中加载此文件,结果显示在页面上(只是孟加拉语单词)。
在 Firefox 中查看页面源代码会显示一个空的 标记,就像我加载的 HTML 代码中一样。
但是使用 Firebug,我可以清楚地看到孟加拉语单词确实在这个标签内。
同样,使用 HttpFox,我可以看到脚本从 Google 接收到的 result
对象。
问题是;
为什么 Firefox 中的页面源没有结果,即使 Firefox 已经渲染了结果并且我可以在那里看到它?
这些程序(Firebug 和 HttpFox)在磁盘上的哪个位置寻找 result
对象?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="https://www.google.com/jsapi?key=MY_KEY">
</script>
<script type="text/javascript">
google.load("language", "1");
function initialize() {
google.language.transliterate(["Mohona"], "en", "bn", function(**result**) {
if (!result.error) {
var container = document.getElementById("transliteration");
if (result.transliterations && result.transliterations.length > 0 &&
result.transliterations[0].transliteratedWords.length > 0) {
container.innerHTML = result.transliterations[0].transliteratedWords[0];
}
}
});
}
google.setOnLoadCallback(initialize);
</script>
</head>
<body>
<div id="transliteration"></div>
</body>
</html>
div 标签中的结果 (Firebug):
结果对象 (HttpFox)。抱歉,图像质量较差。最后一行黑色文本是整个结果对象(不是橙色条)。
I am new to Java Script. This HTML and Java Script code transliterates an English word to Bengali, using the Google Transliteration API. I load this file in a browser and the result appears on the page (just the Bengali word).
Viewing the page source in Firefox shows an empty <div id="transliteration"></div>
tag, as it was in the HTML code I loaded.
But using Firebug, I can clearly see that the Bengali word is indeed within this tag.
Again, using HttpFox I can see the result
object received by the script from Google.
Questions are;
Why is the page source in Firefox devoid of the result, even though Firefox has rendered the result and I can see it right there ?
Where on disk are these programs (Firebug and HttpFox) looking for the result
object ?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="https://www.google.com/jsapi?key=MY_KEY">
</script>
<script type="text/javascript">
google.load("language", "1");
function initialize() {
google.language.transliterate(["Mohona"], "en", "bn", function(**result**) {
if (!result.error) {
var container = document.getElementById("transliteration");
if (result.transliterations && result.transliterations.length > 0 &&
result.transliterations[0].transliteratedWords.length > 0) {
container.innerHTML = result.transliterations[0].transliteratedWords[0];
}
}
});
}
google.setOnLoadCallback(initialize);
</script>
</head>
<body>
<div id="transliteration"></div>
</body>
</html>
The result in the div tags (Firebug):
The result object (HttpFox). Sorry for the poor quality image. The last line of black text is the entire result object (not the orange bar).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
View is Source 显示最初加载的 HTML。在页面的 JavaScript 运行并修改 DOM 后,Firebug 以 HTML 形式向您显示页面的 DOM。
View is Source shows the HTML as originally loaded. Firebug is showing you the DOM of the page in HTML form, after the page's JavaScript has run and modified the DOM.
JavaScript 在内存中操作 DOM。
因此,磁盘上的任何位置都没有已更改的 DOM 的表示。
View-source 将仅显示从服务器接收的数据。
要从 javascript 访问它,您需要执行以下操作,
但要将其写入文件,您将需要更多操作,因为 javascript 无法访问文件系统(出于安全原因)
对于手动保存,您可以将
Javascript manipulates the DOM in-memory.
So there is no representation of the altered DOM anywhere on disk.
View-source will only display the data it received from the server.
To access it from javascript you need to do
but to write it to a file you will need more than that because javascript can not access the filesystem (for security reasons)
For manual saving, you can just put the contents of the
html
variable in a<textarea>
and copy/paste in a file.