Firefox 插件:隐藏<浏览器>>在 XUL 覆盖中?
我正在尝试在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
覆盖总是必须扩展现有元素。如果您在叠加层的顶层有一个标签,其 ID 尚不存在于文档中,则该元素将被忽略(
标签是规则中值得注意的例外) )。这种情况发生在您的情况下,ID
bContainer
在您覆盖的文档中不存在,因此您的
标记将被忽略。例如,此机制允许在同一覆盖中包含 Firefox 和 SeaMonkey 工具菜单的内容 - 该菜单在 Firefox 和 SeaMonkey 中具有不同的 ID,因此覆盖 SeaMonkey 菜单的部分在 Firefox 中会被忽略,反之亦然。如果要向文档添加元素,则需要覆盖其根元素。对于 Firefox 浏览器窗口,它看起来像这样(注意
main-window
是根元素的 ID):旁注:要通过元素的 ID 访问元素,您需要使用
document.getElementById()
: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 IDbContainer
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):A side-note: to access an element by its ID you need to use
document.getElementById()
: