Onkeypress occurs when the user presses and releases any alphanumeric key. System buttons (for example, arrow keys and function keys) cannot be identified.
<Body onkeydown = "enter ()"> // Add onkeydown to the body tag
<Script language = "JavaScript">
Function enter ()
{
If (window. event. keyCode = 13) // enter's KEYCODE value is 13, which can be controlled through monitoring.
{
Window. event. returnValue = false;
}
}
</SCRIPT>
Or
Add the Onkeydown event function in the area to be intercepted, and write the following statement in the execution function:
If (window. event. keyCode = 13) window. event. keyCode = 0
In this way, the Enter key is canceled.
To simulate the Tab key, write it
If (window. event. keyCode = 13) window. event. keyCode = 9
It will jump to another element.
Capture the onKeydown event of the entire page:
Document. onkeydown = function (){
Alert (event. keyCode) // you can view the keyCode of each key.
If (event. keyCode = 13)
Event. keyCode = 9; // simulate as a Tab
}
Shield other buttons
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Noscript> <meta http-equiv = "refresh" content = "0; url = about: noscript"> </noscript>
<Title> right-click, Ctrl + N, Shift + F10, Alt + F4, F11, F5 refresh, and backspace </title>
</Head>
<Body>
<Script language = "Javascript"> <! --
// Shield right-click, Ctrl + N, Shift + F10, F11, F5 refresh, and return keys
Function document. oncontextmenu () {event. returnValue = false;} // right-click the screen
Function window. onhelp () {return false} // block F1 help
Function document. onkeydown ()
{
If (window. event. altKey )&&
(Window. event. keyCode = 37) | // mask Alt + direction key seek
(Window. event. keyCode = 39) // mask Alt + direction key →
{
Alert ("You are not allowed to use ALT + arrow keys to move forward or backward the webpage! ");
Event. returnValue = false;
}
/* Note: this does not really block Alt + direction keys,
Because when the Alt + direction key pop-up warning box is displayed, press and hold the Alt key,
With the mouse clicked off the warning box, this blocking method will become invalid. If
Which of the following methods does the master really block the Alt key. */
If (event. keyCode = 8) | // shield the unregeed deletion key
(Event. keyCode = 116) | // block the F5 refresh key
(Event. ctrlKey & event. keyCode = 82) {// Ctrl + R
Event. keyCode = 0;
Event. returnValue = false;
}
If (event. keyCode = 122) {event. keyCode = 0; event. returnValue = false;} // block F11
If (event. ctrlKey & event. keyCode = 78) event. returnValue = false; // block Ctrl + n
If (event. shiftKey & event. keyCode = 121) event. returnValue = false; // block shift + F10
If (window. event. srcElement. tagName = "A" & window. event. shiftKey)
Window. event. returnValue = false; // block shift with the left mouse button to open a new page
If (window. event. altKey) & (window. event. keyCode = 115) // block Alt + F4
{
Window. showModelessDialog ("about: blank", "", "dialogWidth: 1px; dialogheight: 1px ");
Return false;
}
}
</Script>
Shield right-click, Ctrl + N, Shift + F10, Alt + F4, F11, F5 refresh, and return key
</Body>