Jquery / JS阻止了浏览器中的右键菜单 [英] Jquery/JS prevent right click menu in browsers

查看:816
本文介绍了Jquery / JS阻止了浏览器中的右键菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的div有一个右键单击弹出菜单:

I have my div with a right click popup menu:

// Attatch right click event to folder for extra options
$('#fBox' + folderID).mousedown(function(event) {
    if (event.which == 3) {

        // Set ID
        currRClickFolder = folderID;

        // Calculate position to show popup menu
        var height = $('#folderRClickMenu').height();
        var width = $('#folderRClickMenu').width();
        leftVal = event.pageX - (width / 2) + "px";
        topVal = event.pageY - (height) + "px";
        $('#folderRClickMenu').css({ left: leftVal, top: topVal }).show();

    }
});

但此元素的浏览器仍会弹出默认菜单(复制/粘贴/属性等)。有什么方法可以禁用它吗?我试过返回false而不是运气。

But the browser for this element still pops up the default menu (copy/paste/properties etc). Any way to disable this? I've tried return false but not luck.

推荐答案

你可以通过附加oncontextmenu =return false来禁用右键单击。到你的身体标签。

You can disable the right click by appending oncontextmenu="return false;" to your body tag.

<body oncontextmenu="return false;">

这篇关于Jquery / JS阻止了浏览器中的右键菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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