Firefox Addons: Hidden in XUL Overlay?

前端 未结 1 1514
暖寄归人
暖寄归人 2021-01-16 20:41

I\'m trying to load and manipulate a hidden tag in my overlay (part of my addon\'s functionality) in my Firefox Addon. But, I can\'t access an

相关标签:
1条回答
  • 2021-01-16 21:41

    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);
    
    0 讨论(0)
提交回复
热议问题