我花了很长时间尝试不同的东西来实现这个功能,但没有任何功能,文档没有什么帮助。从Firefox扩展中访问iFrame的dom
我正试图填充一个表格,我动态注入到一个页面的iframe。要注入iframe我做:
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);
它工作正常,并且会触发populate()方法。我的问题是获取该iframe的文档或窗口对象。我试过以下所有内容:
myObject.iframe.window
myObject.iframe.document
myObject.iframe.content
但这些都是未定义的。
我也试过路过事件对象到iframe的load事件监听器,然后做:
event.originalTarget
但是,这也不能工作。
我读了以下文件:
- https://developer.mozilla.org/En/Working_with_windows_in_chrome_code
- https://developer.mozilla.org/en/Code_snippets/Interaction_between_privileged_and_non-privileged_pages
但无论哪种,我不理解它,或者它只是没有适当解释。
任何人都可以点亮一下吗?
谢谢!
这可能适用于浏览器,但XUL iframe呢?我可以证实Lukasz Salamon的答案正在为XUL工作。 – NoBugs 2013-06-01 02:12:39