Home >Web Front-end >JS Tutorial >Several pieces of code to block mouse and keyboard in javascript_javascript skills

Several pieces of code to block mouse and keyboard in javascript_javascript skills

WBOY
WBOYOriginal
2016-05-16 19:06:48961browse

//Shield the right mouse button, Ctrl n, shift F10, F5 refresh, backspace key
function KeyDown(){
if ((window.event.altKey)&&
((window.event.keyCode= =37)|| //Shield the Alt direction key ←
(window.event.keyCode==39))){ //Shield the Alt direction key →
alert("You are not allowed to use the ALT direction key to move forward or Back to the web page! ");
event.returnValue=false;
}

/* Note: This is not really blocking the Alt direction key,
because when the Alt direction key pops up a warning box , hold down the Alt key,
click on the warning box with the mouse, this shielding method will be ineffective. In the future,
if any expert has a real way to block the Alt key, please let me know. */

if ((event.keyCode==8) || //Shield the backspace delete key
(event.keyCode==116)|| //Shield the F5 refresh key
( event.ctrlKey && event.keyCode==82)){ //Ctrl R
event.keyCode=0;
event.returnValue=false;
}
if ((event.ctrlKey)&& (event.keyCode==78)) //Shield Ctrl n
event.returnValue=false;
if ((event.shiftKey)&&(event.keyCode==121)) //Shield shift F10
event.returnValue=false;
if (window.event.srcElement.tagName == "A" && window.event.shiftKey)
window.event.returnValue = false; //Shield shift plus left mouse button Open a new webpage
if ((window.event.altKey)&&(window.event.keyCode==115)){ //Block Alt F4
window.showModelessDialog("about:blank","", "dialogWidth:1px;dialogheight:1px");
return false;}
}



function init()
{
try{ announceDiv.innerText = announce; }catch(e){}
}
window.onload=init;

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn