I am running into trouble as I am trying to add a menuseparator
dynamically using javascript: I'd created an overlay for the Firefox
context menu (contextAreaContextMenu). Therefore I tried to add a menu
separator dynamically using the following code snippet:
----------------
var contextMenuElement =
document.getElementById("contentAreaContextMenu");
var mySep = document.createElement("menuseparator");
mySep.setAttribute("id", "myID");
mySep.setAttribute("hidden", "false");
contextMenuElement.appendChild(mySep);
---------------
Unfortunately this does not work. I cannot see the separator &
searching for the id "myID" within the DOM inspector returns with no
result.
Any ideas?
Thanks & best regards,
Martin
> ----------------
> var contextMenuElement =
> document.getElementById("contentAreaContextMenu");
> var mySep = document.createElement("menuseparator");
>
You ought to use createElementNS.
> mySep.setAttribute("id", "myID");
Use mySep.id = "myID", although it shouldn't matter.
> mySep.setAttribute("hidden", "false");
Only one value makes sense for the "hidden" attribute - "true". By
default, this attribute doesn't exist, so the element is not hidden.
There's hidden -property- (mySep.hidden) which -is- a boolean.
> contextMenuElement.appendChild(mySep);
sometimes you need to first add the element to the DOM and set the
properties later, but the order shouldn't matter in this case.
Nickolay
> ---------------
>
> Unfortunately this does not work. I cannot see the separator &
> searching for the id "myID" within the DOM inspector returns with no
> result.
>
>
> Any ideas?
>
> Thanks & best regards,
> Martin
>
> _______________________________________________
> dev-tech-xul mailing list
> dev-te...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-tech-xul
>
> Where does this code run? Did you check the Error/JavaScript console
> for messages? Does the overlay itself get applied successfully?
The overlay is applied successfully. I am already creating the
menuitems for my the contextmenu dynamically. This works just fine. The
Error/JS console does not print out any messages. That's why I am so
confused.
I followed your advices, but no separator there :(
Best regards,
Martin
Nickolay
>I am running into trouble as I am trying to add a menuseparator
>dynamically using javascript: I'd created an overlay for the Firefox
>context menu (contextAreaContextMenu). Therefore I tried to add a menu
>separator dynamically using the following code snippet:
>----------------
>var contextMenuElement =
>document.getElementById("contentAreaContextMenu");
>var mySep = document.createElement("menuseparator");
>mySep.setAttribute("id", "myID");
>mySep.setAttribute("hidden", "false");
>contextMenuElement.appendChild(mySep);
>---------------
>Unfortunately this does not work. I cannot see the separator &
>searching for the id "myID" within the DOM inspector returns with no
>result.
>Any ideas?
>Thanks & best regards,
>Martin
I have ever met with the same problem. But after failed, I thought , maybe
stupid,
that phenomenon is right. Because the DOM parser doesn't have any
information about
that the dynamical inserted element is an Overlay. The DOM parser work the
element
as a normal element.
I have not found any way how to solve this problem as yet.
Thanks for your attention.
_________________________________________________________________
免费下载 MSN Explorer: http://explorer.msn.com/lccn/
Perhaps Martin can post the correct code he's using now.
Nickolay
Sorry for not responding for such a long time!
The new google groups layout attracted my attention and now here I am,
reading my recent posts ;)
So here is what I did:
1) I created an overlay for the contextmenu with an 'container' element
<popup id="contentAreaContextMenu"></popup>
2) After that I added (menu-items and) separators with the following
snippet:
var contextMenuElement =
document.getElementById("contentAreaContextMenu");
var veryFirstElement = contextMenuElement.firstChild;
var mySep = document.createElement("menuseparator");
mySep.id = "myAddonSep1";
contextMenuElement.insertBefore(mySep, veryFirstElement);
It just works. Ok.. In the meanwhile I am doing a bit more (setting
icons, localization, ...) But .. it just works ;)
HTH,
Martin
On 27 Nov. 2006, 09:27, "Nickolay Ponomarev" <asquee...@gmail.com>
wrote:
> On 11/27/06, Deng DongDong <dongdongd...@hotmail.com> wrote:> I have ever met with the same problem. But after failed, I thought , maybe
> > stupid,
> > that phenomenon is right. Because the DOM parser doesn't have any
> > information about
> > that the dynamical inserted element is an Overlay. The DOM parser work the
> > element
> > as a normal element.
> > I have not found any way how to solve this problem as yet.
> > Thanks for your attention.No, this is supposed to work. What code do you use and when does it