Google 网上论坛不再支持新的 Usenet 帖子或订阅项。历史内容仍可供查看。

problems using the menuseparator dynamically

已查看 38 次
跳至第一个未读帖子

mp.mo...@gmail.com

未读,
2006年11月25日 15:17:302006/11/25
收件人
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

未读,
2006年11月26日 09:54:362006/11/26
收件人 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

未读,
2006年11月26日 10:12:162006/11/26
收件人
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

未读,
2006年11月26日 10:14:352006/11/26
收件人
Jeehaaa :) It's working. Thanks a lot Nickolay :)

Nickolay Ponomarev

未读,
2006年11月26日 10:43:162006/11/26
收件人 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

未读,
2006年11月27日 01:22:542006/11/27
收件人 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

未读,
2006年11月27日 03:27:582006/11/27
收件人 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

未读,
2007年1月24日 16:11:072007/1/24
收件人
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 个新帖子