我可以禁用右击在我的网页不使用JavaScript?我问这个问题是因为大多数浏览器允许用户禁用JavaScript。

如果不是,我如何使用JavaScript禁用右键?


当前回答

下面有三种最流行的方法来禁用在网页上单击鼠标右键。

#1使用HTML正文标签

<body oncontextmenu="return false;">

#2使用CSS

body {
    -webkit-user-select: none;  /* Chrome all / Safari all */
    -moz-user-select: none;     /* Firefox all */
    -ms-user-select: none;      /* IE 10+ */
    -o-user-select: none;
    user-select: none;
}

#3使用JavaScript

document.addEventListener('contextmenu', e => e.preventDefault());

其他回答

试试这个

<script language=JavaScript>
//Disable right mouse click Script

var message="Function Disabled!";

function clickIE4(){
if (event.button==2){
alert(message);
return false;
 }
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("alert(message);return false")

</script>

试试这段代码禁用检查元素选项

    jQuery(document).ready(function() {
    function disableSelection(e) {
        if (typeof e.onselectstart != "undefined") e.onselectstart = function() {
            return false
        };
        else if (typeof e.style.MozUserSelect != "undefined") e.style.MozUserSelect = "none";
        else e.onmousedown = function() {
            return false
        };
        e.style.cursor = "default"
    }
    window.onload = function() {
        disableSelection(document.body)
    };

    window.addEventListener("keydown", function(e) {
        if (e.ctrlKey && (e.which == 65 || e.which == 66 || e.which == 67 || e.which == 70 || e.which == 73 || e.which == 80 || e.which == 83 || e.which == 85 || e.which == 86)) {
            e.preventDefault()
        }
    });
    document.keypress = function(e) {
        if (e.ctrlKey && (e.which == 65 || e.which == 66 || e.which == 70 || e.which == 67 || e.which == 73 || e.which == 80 || e.which == 83 || e.which == 85 || e.which == 86)) {}
        return false
    };

    document.onkeydown = function(e) {
        e = e || window.event;
        if (e.keyCode == 123 || e.keyCode == 18) {
            return false
        }
    };

    document.oncontextmenu = function(e) {
        var t = e || window.event;
        var n = t.target || t.srcElement;
        if (n.nodeName != "A") return false
    };
    document.ondragstart = function() {
        return false
    };
});

是的,你可以使用HTML和Javascript禁用它。 只需在你的body或元素上添加oncontextmenu="return false;" 它非常简单,只是使用有效的HTML和Javascript,没有jQuery。

如果不使用Javascript,您就无法完成您的要求。您可以选择使用的任何其他技术只能帮助在服务器端组成web页面,然后发送到浏览器。

没有好的解决方案,没有Javascript的解决方案周期。

就这么做

在body标签上写入oncontextmenu

<body oncontextmenu="return false">