Home > Web Front-end > JS Tutorial > body text

Implementation code for disabling right-click, text selection function, and copy button based on jquery_jquery

WBOY
Release: 2016-05-16 17:24:28
Original
1119 people have browsed it

It is also suitable for IE, Firefox, and Google Chrome. The filtered code is as follows:

Copy code The code is as follows:

//禁用右键、文本选择功能、复制按键
$(document).bind(“contextmenu”,function(){return false;});
$(document).bind(“selectstart”,function(){return false;});
$(document).keydown(function(){return key(arguments[0])});

//按键时提示警告
function key(e){
var keynum;
if(window.event){
keynum = e.keyCode; // IE
}else if(e.which){
keynum = e.which; // Netscape/Firefox/Opera
}
if(keynum == 17){
alert(“禁止复制内容!”);
return false;
}
}

//禁用右键、文本选择功能、复制按键
    $(document).bind("contextmenu",function(){return false;});
    $(document).bind("selectstart",function(){return false;});
    $(document).keydown(function(){return key(arguments[0])});

 //按键时提示警告
       function key(e){
            var keynum;
            if(window.event) // IE
              {
                keynum = e.keyCode;
              }
            else if(e.which) // Netscape/Firefox/Opera
              {
                keynum = e.which;
              }
            if(keynum == 17){ alert("禁止复制内容!");return false;}
        }



Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template