Accessing an iFrame's dom from a Firefox Extension

Posted by luisgo on Stack Overflow See other posts from Stack Overflow or by luisgo
Published on 2009-11-23T18:50:52Z Indexed on 2011/02/07 23:25 UTC
Read the original article Hit count: 376

Filed under:
|
|
|

Hi all,

I've spent a long time trying different things to get this to work but nothing does and documentation is not helping much.

I'm trying to populate a form inside an iframe that I dynamically inject into a page. To inject that iframe I do:

myObject.iframe = document.createElement("iframe");
myObject.iframe.setAttribute("src", data.url);
myObject.iframe.setAttribute("id","extension-iframe");
myObject.window.document.getElementById('publisher').appendChild(myObject.iframe);
myObject.iframe.addEventListener("load", function(){
    myObject.populate(data);
}, false);

which works fine and DOES trigger the populate() method. My problem is getting the document or window objects for that iframe. I've tried all of the following:

myObject.iframe.window
myObject.iframe.document
myObject.iframe.content

but these are all undefined.

I also tried passing the event object to that iframe's load event listener and then doing:

event.originalTarget

But that didn't work either.

I am reading the following documentation:

But either I'm not understanding it or it's just not properly explained.

Can anyone shed some light?

Thanks!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about firefox