Home  >  Article  >  Web Front-end  >  Code for disabling right-click and copy-paste functions in JS input text box_javascript skills

Code for disabling right-click and copy-paste functions in JS input text box_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:29:27973browse
Copy code The code is as follows:

function click(e)
{
if (document .all)
{
if (event.button==1||event.button==2||event.button==3)
{
oncontextmenu='return false';
}
}
if (document.layers)
{
if (e.which == 3)
{
oncontextmenu='return false';
}
}
}
if (document.layers)
{
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;
document .oncontextmenu = new Function("return false;")
var trxdyel=true
var hotkey=17 /* hotkey is the key value of the hotkey, which is the ASII code, where 99 represents the c key*/
if (document.layers)
document.captureEvents(Event.KEYDOWN)
function gogo(e)
{
if (document.layers)
{
if (e. which==hotkey && trxdyel)
{
alert('Operation error. Maybe you pressed the wrong key!');
}
}
else if (document.all)
{
if (event.keyCode==hotkey&&trxdyel){ alert('Operation error. Maybe you pressed the wrong key!'); }}
}
document.onkeydown=gogo

Write the above JS code into a JS file, name it xp.js and put it into the Script folder. When quoting, you need to pay attention to setting Charset="gb2312", otherwise the information prompted will be garbled. Page reference:
Copy code The code is as follows:



1. The right mouse button will be completely blocked
Copy code The code is as follows:

oncontextmenu="window.event.returnValue=false"
< ;table border oncontextmenu=return(false)> no can be used in Table
function click() {
if (event.button==2) {
alert(' Sorry, right click is disabled on this page! ')
}
}
document.onmousedown=click

2. Deselect and prevent copying
Copy code The code is as follows:


3. Pasting is not allowed
Copy code The code is as follows:
onpaste= "return false"


4. Prevent copying
Copy code code As follows:
oncopy="return false;" oncut="return false;"


JavaScript shortcut key setting implementation code
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn