Firefox插件:隐藏< browser />在XUL叠加? [英] Firefox Addons: Hidden <browser /> in XUL Overlay?

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

问题描述

我正在尝试加载并操纵我的Firefox Addon中我的覆盖图(部分插件功能)中的隐藏的< browser /> 标签。但是,我无法访问我从文档中叠加的任何元素。



例如,这不工作:

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

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

解决方案

覆盖层总是必须扩展现有的元素。如果您在文档顶部没有标识的顶层标签,则该元素将被忽略(< script> 标签为一个值得注意的例外)。这种情况发生在您的情况下,您正在覆盖的文档中不存在ID bContainer ,因此您的< browser> 标签被忽略。该机制允许在Firefox和SeaMonkey中具有Firefox和SeaMonkey Tools菜单的内容,该菜单在Firefox和SeaMonkey中具有不同的ID,因此在Firefox中忽略覆盖SeaMonkey菜单的部分,反之亦然。



如果要向文档添加元素,则需要覆盖其根元素。对于Firefox浏览器窗口,它将如下所示(请注意, main-window 是根元素的ID):

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

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

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


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?

解决方案

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);

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

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