Firefox插件:隐藏的& lt;浏览器/& gt;在XUL叠加中? [英] Firefox Addons: Hidden <browser /> in XUL Overlay?

查看:66
本文介绍了Firefox插件:隐藏的& lt;浏览器/& gt;在XUL叠加中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Firefox插件中的叠加层(插件功能的一部分)中加载和操作隐藏的<浏览器/> 标记.但是,我无法访问从 document 添加到叠加层中的任何元素.

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.

例如,这不起作用:

<?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?

推荐答案

叠加层始终必须扩展现有元素.如果您在覆盖层的顶层有一个标签,而该标签的ID在文档中尚不存在,则该元素将被忽略(< script> 标签是该规则中的一个值得注意的例外).在您的情况下会发生这种情况,您要覆盖的文档中不存在ID bContainer ,因此,您的< browser> 标记将被忽略.例如,这种机制可以使Firefox和SeaMonkey Tools菜单的内容位于同一叠加层中-该菜单在Firefox和SeaMonkey中具有不同的ID,因此,在Firefox中可以忽略叠加SeaMonkey菜单的部分,反之亦然.

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.

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

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>

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

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

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

这篇关于Firefox插件:隐藏的&amp; lt;浏览器/&amp; gt;在XUL叠加中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆