简体   繁体   中英

Creating on popupmenu on a right-click(contextmenu) event on a document not working as expected

I'm trying to listen to a right-click event on a document, on which a pop-up menu (goog.ui.popupmenu) should be created. The very first time, the menu is created on right-click, but after that its created even on left clicks.

I tried detaching the object from the element when the first time event is received. But that doesnt seem to work.

Here's what I'm doing:

goog.events.listen(element, goog.events.EventType.CONTEXTMENU, function(e) {
     e.preventDefault();
     this.menu();
}, true, this);

I'm testing this code on Chrome.

Your code works fine for me (at least the part which you shared). It reacts to the first and every other right click and never reacts to left click.

But you can make the element to react to right click by supplying true as the opt_contextMenu parameter of the attach method, such as like this:

popupMenu.attach(element, goog.positioning.Corner.TOP_LEFT, goog.positioning.Corner.BOTTOM_LEFT, true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM