[英]How to get reference to XUL iframe that contains a window
从 Firefox 扩展有一种方法可以获取包含内容 HTML window 的 XUL iframe/浏览器。 注意我不是问如何获取当前浏览器 (gBrowser) 或 browser.xul window。 我有目标/内容 HTML window 句柄,我想在 XUL 树中跟进它(到包含它的 XUL 元素)。
getting-a-reference-to-the-parent-iframe建议对于 HTML iframe,您需要遍历所有 iframe 以找到正确的 iframe,但我想知道是否有一些特定于 Firefox 的访问包含 XUL iframe 的方法(来自特权/扩展代码)。
aWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShell)
.chromeEventHandler
请注意,在 Firefox 3.6 和之前的版本中,这会返回一个 XPCNativeWrapper,然后您可能希望将其解包。
From an extension's point of view, "window" is the top level chrome window of Firefox, containing special <vbox> and <hbox> elements for the buttons, toolbars, etc. You can see these in the DOM Inspector if you go to File -> 检查 Chrome 文档 ->(浏览器窗口)。 要从扩展的 Javascript 获取当前页框,请使用content 。
要获取外部 window,请使用window.parent或 window.parent.top。 如果内部文档是 chrome 特权,也许您可以检查 window 级别的特殊属性或变量。
在扩展中,您的代码通常已经在主 window 中执行,因此您只需使用gBrowser
(参见https://developer.mozilla.org/en/Code_snippets/Tabbed_browser#From_main_window )。
如果您的代码在不同的 window 中运行,那么 window 中介是您的朋友: https://developer.mozilla.org/en/Code_snippets/Tabbed
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.