简体   繁体   English

如何检测上下文菜单何时被隐藏?

[英]How can I detect when the context menu has been hidden?

I'm developing an extension for Google Chrome using JQuery and Javascript and I want to set a variable to "true" when the user open the context menu and set the variable to "false" when the context menu is hidden. 我正在开发使用JQuery和Javascript的Google Chrome扩展程序,我想在用户打开上下文菜单时将变量设置为“ true”,而在隐藏上下文菜单时将变量设置为“ false”。

I can detect when it's open with the following code: 我可以使用以下代码检测它何时打开:

var contextMenuOpen;
$(document).on("contextmenu", function(e){
    contextMenuOpen = true;
});

But I don't know how can I detect if it is hidden. 但是我不知道如何检测它是否被隐藏。

Thanks in advance and sorry for my English. 在此先感谢您,我的英语很抱歉。

in the context menu definition you can implement the hide event function 在上下文菜单定义中,您可以实现hide事件功能

events: {
hide: function(opt){
//.. do what you need
}
}

or i everywhere you need you could check if context menu div has the "context-menu-active" class 或者我到处都需要,您可以检查上下文菜单div是否具有“ context-menu-active”类

if ("#myDiv").hasClass("context-menu-active")) {
$("#myDiv").contextMenu("hide");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检测移动浏览器何时返回到已暂停的页面? - How can I detect when a mobile browser returns to a page that has been paused? 如何检测何时将新元素添加到 jquery 的文档中? - How can I detect when a new element has been added to the document in jquery? 如何在网页中检测是否已启用Chrome扩展程序(已禁用) - How can I detect in web page if a Chrome Extension has been enabled (after having been disabled) 萤火虫-如何检测已调用的函数或从何处调用了函数 - firebug - how can I detect what functions have been called or from where a function has been called 我怎么知道数组元素何时被弹出() - How can I tell when an array element has been .popped() 如何在不移动窗口的情况下使用JavaScript检测div滚动了多远? - How can I use JavaScript to detect how far a div has been scrolled by without the window moving? 如何检测是否已实例化jQuery Lightslider,以及如何清除实例 - How can I detect if jQuery lightslider has been instantiated, and how to clear instance if yes 我可以检测网页是否已被Google翻译过? - Can i detect if a web page has been translated by Google? 如何检测何时使用 jQuery 按下了删除键? - How do I detect when the delete key has been pressed with jQuery? 我可以使用Javascript检测复选框是否被选中吗? - Can I use Javascript to detect whether a checkbox has been checked?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM