是否存在浏览器上下文菜单的关闭事件 [英] Is there a close event for the browser contextmenu

查看:174
本文介绍了是否存在浏览器上下文菜单的关闭事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery捕获 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.

使用类似下面的内容可以捕捉到一些情况,但几乎不是全部:

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:


  • 浏览器失去焦点

  • 选择上下文菜单中的选项

  • 用户点击浏览器中的任意位置不在页面上

注意:我没有使用jQuery上下文菜单,我只是使用它来捕捉事件。

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

推荐答案

以下代码可以帮助您。 jsfiddle

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

这篇关于是否存在浏览器上下文菜单的关闭事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆