Firefox 插件:隐藏<浏览器>>在 XUL 覆盖中?

发布于 2024-12-04 02:49:55 字数 780 浏览 0 评论 0原文

我正在尝试在 Firefox 插件中加载和操作覆盖层(插件功能的一部分)中隐藏的 标签。但是,我无法从 document 访问我在叠加层中添加的任何元素。

例如,这不起作用:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="chrome://foxy_bucks/skin/overlay.css" type="text/css"?>
<!DOCTYPE overlay SYSTEM "chrome://foxy_bucks/locale/overlay.dtd">
<overlay id="foxy_bucks-overlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    <browser id="bContainer" src="http://google.com/"></browser>
    <script type="text/javascript">
        window.addEventListener("load", function(){
            alert(document.bContainer.src);
        }, false);
    </script>
</overlay>

有人能指出我正确的方向吗?

I'm trying to load and manipulate a hidden <browser /> tag in my overlay (part of my addon's functionality) in my Firefox Addon. But, I can't access any of the elements I add in my overlay from document.

For example, this isn't working:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="chrome://foxy_bucks/skin/overlay.css" type="text/css"?>
<!DOCTYPE overlay SYSTEM "chrome://foxy_bucks/locale/overlay.dtd">
<overlay id="foxy_bucks-overlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    <browser id="bContainer" src="http://google.com/"></browser>
    <script type="text/javascript">
        window.addEventListener("load", function(){
            alert(document.bContainer.src);
        }, false);
    </script>
</overlay>

Could someone point me into the right direction?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

卸妝后依然美 2024-12-11 02:49:55

覆盖总是必须扩展现有元素。如果您在叠加层的顶层有一个标签,其 ID 尚不存在于文档中,则该元素将被忽略(

如果要向文档添加元素,则需要覆盖其根元素。对于 Firefox 浏览器窗口,它看起来像这样(注意 main-window 是根元素的 ID):

<overlay id="foxy_bucks-overlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  <window id="main-window">
    <browser id="bContainer" src="http://google.com/"></browser>
  </window>
  ...
</overlay>

旁注:要通过元素的 ID 访问元素,您需要使用 document.getElementById()

alert(document.getElementById("bContainer").src);

Overlays always have to extend an existing element. If you have a tag at the top level of an overlay with an ID that doesn't yet exist in the document then this element is simply ignored (<script> tags being a noteworthy exception from the rule). This happens in your case, the ID bContainer doesn't exist in the document you are overlaying so your <browser> tag is simply ignored. This mechanism allows for example having content for the Firefox and SeaMonkey Tools menu in the same overlay - this menu has a different ID in Firefox and SeaMonkey so the section overlaying the SeaMonkey menu is simply ignored in Firefox and vice versa.

If you want to add an element to the document then you need to overlay its root element. For the Firefox browser window it would look like this (note that main-window is the ID of the root element):

<overlay id="foxy_bucks-overlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  <window id="main-window">
    <browser id="bContainer" src="http://google.com/"></browser>
  </window>
  ...
</overlay>

A side-note: to access an element by its ID you need to use document.getElementById():

alert(document.getElementById("bContainer").src);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文