Is there a close event for the browser contextmenu

I’m catching the contextmenu event using jQuery like this:

$(document.body).on("contextmenu", function(e){
    //do stuff here
});

So far, so good. Now I want to execute some code when it closes but I can’t seem to find a correct solution for this.

  • How do I trigger the browser context menu on an element. (As if the user right-clicked)
  • jQuery Right-Click Context Menu Help!
  • How to disable right-click context-menu in javascript
  • Can we disable right clicking on Anchor Tag in HTML
  • Disable the context menu in chrome apps?
  • how to disable default context menu for certain elements in mozilla using Prototype?
  • Using something like the following would catch some of the cases, but not nearly all:

    $(document.body).on("contextmenu click", function(e){});
    

    It wouldn’t be executed when:

    • the browser loses focus
    • an option in the contextmenu is chosen
    • the user clicks anywhere in the browser that’s not on the page

    note: I’m not using a jQuery context menu, I’m just using it to catch the event.

  • Enabling jQuery contextMenu item on ajax request
  • Multiple context menu entries for a chrome extension?
  • invoke primefaces context menu from java script
  • Chrome Context Menu Child Item functions launching all at once
  • How do I trigger the browser context menu on an element. (As if the user right-clicked)
  • Adding copy & paste functionalities to a custom menu of a webapp
  • One Solution collect form web for “Is there a close event for the browser contextmenu”

    Following code may help you. jsfiddle

    var isIntextMenuOpen ;
    $(document).on("contextmenu", function(e){
    
        isIntextMenuOpen = true;
    });
    function hideContextmenu(e){
           if(isIntextMenuOpen ){
                console.log("contextmenu closed ");
           }
    
         isIntextMenuOpen = false;
    }
    $(window).blur(hideContextmenu);
    
    $(document).click(hideContextmenu);