Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

problems using the menuseparator dynamically

37 views
Skip to first unread message

mp.mo...@gmail.com

unread,
Nov 25, 2006, 3:17:30 PM11/25/06
to
Hi folks,

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

Nickolay Ponomarev

unread,
Nov 26, 2006, 9:54:36 AM11/26/06
to mp.mo...@gmail.com, dev-te...@lists.mozilla.org
On 25 Nov 2006 12:17:30 -0800, mp.mo...@gmail.com

<mp.mo...@gmail.com> wrote:
> Hi folks,
>
> 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:
>
Where does this code run? Did you check the Error/JavaScript console
for messages? Does the overlay itself get applied successfully?

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

mp.mo...@gmail.com

unread,
Nov 26, 2006, 10:12:16 AM11/26/06
to
Hi Nicolay,


> 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

mp.mo...@gmail.com

unread,
Nov 26, 2006, 10:14:35 AM11/26/06
to
Jeehaaa :) It's working. Thanks a lot Nickolay :)

Nickolay Ponomarev

unread,
Nov 26, 2006, 10:43:16 AM11/26/06
to mp.mo...@gmail.com, dev-te...@lists.mozilla.org
On 26 Nov 2006 07:14:35 -0800, mp.mo...@gmail.com

<mp.mo...@gmail.com> wrote:
> Jeehaaa :) It's working. Thanks a lot Nickolay :)
>
What was the problem?

Nickolay

Deng DongDong

unread,
Nov 27, 2006, 1:22:54 AM11/27/06
to dev-te...@lists.mozilla.org
>Hi folks,

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

Nickolay Ponomarev

unread,
Nov 27, 2006, 3:27:58 AM11/27/06
to Deng DongDong, dev-te...@lists.mozilla.org
On 11/27/06, Deng DongDong <dongdo...@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
run? Do you get any errors in the JS console?

Perhaps Martin can post the correct code he's using now.

Nickolay

mp.mo...@gmail.com

unread,
Jan 24, 2007, 4:11:07 PM1/24/07
to
Hi folks,

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

0 new messages