Code for disabling the right-click and copy-and-paste functions in the JS input text box

Source: Internet
Author: User

Copy codeThe 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 an 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 have pressed the wrong key! ');
}
}
Else if (document. all)
{
If (event. keyCode = hotkey & trxdyel) {alert ('Operation error. Maybe you have pressed the wrong key! ');}}
}
Document. onkeydown = gogo

Write the above JS Code to the JS file and name it xp. js and put it into the Script folder. When referencing the Code, set Charset = "gb2312". Otherwise, the prompt message will be garbled. Page reference:
Copy codeThe Code is as follows:
<Script src = "../Script/xp. js" type = "text/javascript" charset = "gb2312"> </script>

1. the right mouse button will be completely shielded
Copy codeThe Code is as follows:
Oncontextmenu = "window. event. returnValue = false"
<Table border oncontextmenu = return (false)> <td> no </table>
Function click (){
If (event. button = 2 ){
Alert ('Sorry, right-click this page to disable it! ')
}
}
Document. onmousedown = click

2. Cancel selection and prevent Replication
Copy codeThe Code is as follows: <body onselectstart = "return false">

3. Do not paste
Copy codeThe Code is as follows: onpaste = "return false"

4. Prevent Replication
Copy codeThe Code is as follows: oncopy = "return false;" oncut = "return false ;"

JavaScript shortcut key setting implementation code

Related Article

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.