Javascript tips for disabling the right-click and copy-and-paste functions in the JSinput text box

Source: Internet
Author: User
Due to project requirements, some text boxes need to disable the right-click and copy-and-paste functions, which were just implemented in JS yesterday. 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 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:

The Code is as follows:


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.