Sometimes, for some reason, you need to disable the user's right-click, Text Selection Function, copy button, and other operations. You can refer to the following code for use in IE, firefox, and Google browsers at the same time, the filtered code is as follows:
The Code is as follows:
// Disable right-click, Text Selection, and copy button
$ (Document). bind ("contextmenu", function () {return false ;});
$ (Document). bind ("selectstart", function () {return false ;});
$ (Document). keydown (function () {return key (arguments [0])});
// A warning is prompted when you press the button.
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 ("copying prohibited content !");
Return false;
}
}
// Disable right-click, Text Selection, and copy button
$ (Document). bind ("contextmenu", function () {return false ;});
$ (Document). bind ("selectstart", function () {return false ;});
$ (Document). keydown (function () {return key (arguments [0])});
// A warning is prompted when you press the button.
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 ("copying prohibited content! "); Return false ;}
}
Script
// Shield right-click, Ctrl + N, Shift + F10, F11, F5 refresh, and return keys
Function document. oncontextmenu () {event. returnValue = false;} // right-click the screen
Function window. onhelp () {return false} // block F1 help
Function document. onkeydown (){
If (window. event. altKey )&&
(Window. event. keyCode = 37) | // mask Alt + direction key seek
(Window. event. keyCode = 39) {// mask Alt + direction key →
Alert ("You are not allowed to use ALT + arrow keys to move forward or backward the webpage! ");
Event. returnValue = false;
} If (event. keyCode = 8) | // block the unregeed deletion key
(Event. keyCode = 116) | // block the F5 refresh key
(Event. ctrlKey & event. keyCode = 82) {// Ctrl + R
Event. keyCode = 0;
Event. returnValue = false;
}
If (event. keyCode = 122) {event. keyCode = 0; event. returnValue = false;} // block F11
If (event. ctrlKey & event. keyCode = 78) event. returnValue = false; // block Ctrl + n
If (event. shiftKey & event. keyCode = 121) event. returnValue = false; // block shift + F10
If (window. event. srcElement. tagName = "A" & window. event. shiftKey)
Window. event. returnValue = false; // block shift with the left mouse button to open a new page
If (window. event. altKey) & (window. event. keyCode = 115) {// block Alt + F4
Window. showModelessDialog ("about: blank", "", "dialogWidth: 1px; dialogheight: 1px ");
Return false;
}
}
Script