Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
835
How to cancel Google context menu on toolbar right-click
posted

I have programatically added popup menu's to various toolbar buttons so that when I right click on the button the menu appears.  However, the Google context menu also appears.

The right click is captured in the tb_Click event (client-side) and I popup the menu within this event routine with igmenu_showMenu.  The menu appears, along with the Google context menu.  I have tried setting oEvent.event.cancelBubble  = true and oEvent.event.returnValue = false, and also Return false, but none of these stop Goggle.

I am using IE7, if that could make a difference.

Any suggestions?

  • 835
    posted

    I determined that had to capture the 'oncontextmenu' at the document level to stop this.

    Basically, its a matter of returning False for the when the oncontextmenu event occurs, but since I didn't want to do this except for when I had previously captured the right click, I did the following:

    CapturedRightClick = false;
    document.attachEvent('oncontextmenu', OnContextMenu);

    function OnContextMenu() {
        if (CapturedRightClick) {
            CapturedRightClick = false;
            return false}}

    function tbClick(oToolbar, oButton, oEvent) {
         if (oEvent.event.button == 2) {
            CapturedRightClick = true;
            igmenu_showMenu(menuname, oEvent, oEvent.event.x, oEvent.event.y)}}