Question

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"/>

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;

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.

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?

Was it helpful?

Solution

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);
    }

replace "DomLoadedEventHandler" with your event handler name.

I recommend that you take a look at the official site of Mozilla to learn everything about Firefox extensions

http://developer.mozilla.com

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top