JS input text box disables the right key and copy paste function code _javascript tips

Source: Internet
Author: User
Copy Code code 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, is the ASII code, here 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 button! ');
}
}
else if (document.all)
{
if (Event.keycode==hotkey&&trxdyel) {alert (' Operation error ') Maybe you pressed the wrong button! '}
}
Document.onkeydown=gogo

The above JS code to write to the JS file named Xp.js and put into the script folder, the reference needs to pay attention to set the charset= "gb2312", or the message will be prompted garbled. Page reference:
Copy Code code as follows:

<script src= ". /script/xp.js "type=" Text/javascript "charset=" gb2312 "></script>

1. Will completely screen the right mouse button
Copy Code code as follows:

oncontextmenu= "Window.event.returnvalue=false"
<table border Oncontextmenu=return (false) > <td> no</table> available for table
function Click () {
if (event.button==2) {
Alert (' Sorry, this page disables the right button! ')
}
}
Document.onmousedown=click

2. Deselect, prevent replication
Copy Code code as follows:
<body onselectstart= "return false" >


3. No pasting
Copy Code code as follows:
Onpaste= "return False"


4. Prevention of duplication
Copy Code code as follows:
Oncopy= ' return false; ' oncut= ' return false;


JavaScript shortcut key Settings Implementation code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.