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: