在这种情况下如何重新启用上下文菜单?

发布于 2024-09-04 12:24:10 字数 302 浏览 1 评论 0原文

document.addEventListener('contextmenu', function (e) {
    e.preventDefault()
    e.stopPropagation()
    e.returnValue = false
    e.cancleBubble = true
})

决不?

编辑: document.oncontextmenu = null 不起作用。

PS 我无法获得侦听器功能的参考,因为我不是阻止上下文菜单的站点的所有者。

document.addEventListener('contextmenu', function (e) {
    e.preventDefault()
    e.stopPropagation()
    e.returnValue = false
    e.cancleBubble = true
})

No way?

Edit: document.oncontextmenu = null does not work.

P.S. I cannot have the reference of the listener function since I am not the owner of the site preventing the context menu.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ゞ花落谁相伴 2024-09-11 12:24:10

在这种情况下我使用我的书签:

javascript:(function(w){
    var arr = ['contextmenu','copy','cut','paste','mousedown','mouseup','beforeunload','beforeprint'];
    for(var i = 0, x; x = arr[i]; i++){
        if(w['on' + x])w['on' + x] = null;
        w.addEventListener(x, function(e){e.stopPropagation()}, true);
    };
    for(var j = 0, f; f = w.frames[j]; j++){try{arguments.callee(f)}catch(e){}}})(window);

I use my bookmarklet in such cases:

javascript:(function(w){
    var arr = ['contextmenu','copy','cut','paste','mousedown','mouseup','beforeunload','beforeprint'];
    for(var i = 0, x; x = arr[i]; i++){
        if(w['on' + x])w['on' + x] = null;
        w.addEventListener(x, function(e){e.stopPropagation()}, true);
    };
    for(var j = 0, f; f = w.frames[j]; j++){try{arguments.callee(f)}catch(e){}}})(window);
↙温凉少女 2024-09-11 12:24:10

如果您真的绝望,请尝试在调用 addEventListener 之前添加此内容。它适用于 FF 和 Chrome。我没有检查其他任何东西。

document.superListener = document.addEventListener;
document.addEventListener = function(type, listener, useCapture){
    if(type != 'contextmenu')
        document.superListener(type, listener, !!useCapture);
};

这可能不是最好的做事方式,但它应该是针对您的具体示例完成的工作:)

If you are really desperate, try adding this before the addEventListener is called. It works in both FF and Chrome. I didn't check anything else.

document.superListener = document.addEventListener;
document.addEventListener = function(type, listener, useCapture){
    if(type != 'contextmenu')
        document.superListener(type, listener, !!useCapture);
};

It may not be the best way to do things, but it should be the job done on your specific example :)

幻梦 2024-09-11 12:24:10

为什么不分配右键单击事件而不是禁用上下文菜单呢?

http://abeautifulsite.net/2008/05/jquery-right-click -插件/

Rather than disabling the context menu, why don't you assign the right click event?

http://abeautifulsite.net/2008/05/jquery-right-click-plugin/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文