在XUL中,我如何知道浏览器标签已经完成加载? [英] In XUL, how do I know a browser-tag has finished loading?
问题描述
我正在开发基于本教程这是一个FF 2.0扩展(本教程的第二部分在此网址)
I'm developing a firefox extension based on this tutorial which is a FF 2.0 extension (second part of the tutorial is at this url)
主要的是重要的是它使用
The main thing that is important is that it uses
<iframe id="contentview" src="http://www.ibm.com/developerworks/web" flex="2"/>
在后端代码中,当点击GO按钮时,会发生这种情况:
In the backend code, when clicking the GO button, this happens:
contentview.contentDocument.location.href = urlbox.value;
//Use Firefox XPath to get the raw text of the document
var doctext = contentview.contentDocument.evaluate(
"string(.)", document, null, XPathResult.STRING_TYPE, null).stringValue;
我收到xpath的错误,但这不是我的问题。我使用FF 3.0的问题是contentDocument值是指加载的旧站点,而不是由href-change加载的站点。
I get an error with the xpath, but that's not my question. The issue I have with FF 3.0 is that the contentDocument value refers to the old site loaded, not to the one loaded by the href-change.
所以我的问题是:我如何创建一个类似的窗口,但是当加载的文档完成时会被通知某人,所以我可以访问其DOM?
So my question is: how can I create a similar window, but be notified someone when the loaded document is complete, so I can access its DOM?
推荐答案
更新:
首先,您需要处理窗口的加载事件,然后向iframe元素添加事件侦听器
Updated: first you need to handle the load event of the window then you add an event listener to the iframe element
window.addEventListener("load",Listen,false);
function Listen()
{
var frame = document.getElementById("contentview");
frame.addEventListener("DOMContentLoaded", DomLoadedEventHandler, true);
}
function DomLoadedEventHandler() {
var frame = document.getElementById("contentview");
alert(frame.contentDocument.location.href);
}
将DomLoadedEventHandler替换为您的事件处理程序名称。
replace "DomLoadedEventHandler" with your event handler name.
我建议您查看Mozilla的官方网站,了解有关Firefox扩展的所有信息
I recommend that you take a look at the official site of Mozilla to learn everything about Firefox extensions
这篇关于在XUL中,我如何知道浏览器标签已经完成加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!