有一种方法可以从 Firefox 扩展获取包含内容 HTML 窗口的 XUL iframe/浏览器。注意我不是问如何获取当前浏览器(gBrowser)或 browser.xul 窗口。我有目标/内容 HTML 窗口句柄,我想在 XUL 树中跟踪它(到包含它的 XUL 元素)。
获取a-reference-to-the-parent-iframe建议对于 HTML iframe,您需要遍历所有 iframe 才能找到正确的 iframe,但我想知道是否有某种特定于 Firefox 的方式来访问包含 XUL iframe(从特权/扩展代码)。
From a Firefox extension is there a way to get the XUL iframe/browser that contains a content HTML window. Note I am not asking how to get the current browser (gBrowser) or the browser.xul window. I have target/content HTML window handle, I want to follow it up in the XUL tree (to the XUL element that contains it).
getting-a-reference-to-the-parent-iframe suggest that for HTML iframes you need to iterate through all iframes to find the right one, but I am wondering if there is some Firefox-specific way of accessing a containing XUL iframe (from privileged/extension code).
发布评论
评论(3)
请注意,在 Firefox 3.6 及之前的版本中,这会返回一个 XPCNativeWrapper,然后您可能想要解开它。
Note that in Firefox 3.6 and previously this returns an XPCNativeWrapper which you then probably want to unwrap.
在扩展中,您的代码通常已经在主窗口中执行,因此您只需使用
gBrowser
(请参阅 https://developer.mozilla.org/en/Code_snippets/Tabbed_browser#From_main_window)。如果您的代码在不同的窗口中运行,那么窗口中介器就是您的朋友:https://developer。 mozilla.org/en/Code_snippets/Tabbed_browser#From_a_dialog
In an extension your code is typically already executing in the main window, so you simply use
gBrowser
(see https://developer.mozilla.org/en/Code_snippets/Tabbed_browser#From_main_window).If your code runs in a different window then window mediator is your friend: https://developer.mozilla.org/en/Code_snippets/Tabbed_browser#From_a_dialog
从扩展的角度来看,“window”是 Firefox 的顶级 chrome 窗口,包含特殊的 。和 按钮、工具栏等元素。如果您转到“文件”->“文件”,则可以在 DOM 检查器中看到这些元素。检查 Chrome 文档 -> (浏览器窗口)。要从扩展程序的 Javascript 获取当前页面框架,请使用 content。
要获取外部窗口,请使用 window.parent 或 window.parent.top。如果内部文档是 chrome 特权的,也许您可以在窗口级别检查特殊属性或变量。
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 -> Inspect Chrome Document -> (Browser Window). To get the current page frame from extension's Javascript, use content.
To get the outer window, use window.parent, or window.parent.top. If the inner document is chrome-privileged, perhaps you could check for a special attribute or variable at the window level.