Home >Web Front-end >JS Tutorial >Usage examples of shielding in js_javascript skills

Usage examples of shielding in js_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:27:571196browse

js屏蔽效果

复制代码 代码如下:

/**Block F1 help*/
window.onhelp = function(){return false;}
/**
*Block F5, Ctrl N, Shift F10, Alt F4
*If you want to block other keys, find the corresponding keyCode and follow this method
*/
document.onkeydown = function(event){
event = window.event || event;
if(event.keyCode==116 || (event.ctrlKey && event.keyCode==78) || (event.shiftKey && event.keyCode==121) || (event.altKey && event.keyCode==115)){
event.keyCode =0;
event.returnvalue = false;
}
}
/**Block the right mouse button*/
document.oncontextmenu = function(){return false;}
//或者
document.onmousedown = function(event){
event = window.event || event;
if(document.all && event.button == 2) {
event.returnvalue=false;
}
}
/**
* Block the "Back" function (Google)
* @param url The URL to which the page should be redirected
*/
function replaceLocation(url){
document.location.replace(url);
}
/**Block selected web content*/
document.onselectstart=function(){return false;}
/**Block copying of web content*/
document.body.oncopy = function(){return false;}
/**Block and cut web content*/
document.body.oncut = function(){return false;}
/**Block pasting of content into web pages*/
document.body.onpaste = function(){return false;}
/**Block screen copying (clear the clipboard continuously)*/
window.setInterval('window.clipboardData("Text", "")', 100);
/**
* Block viewing of source files ( )
*/
function clear() {
var source=document.body.firstChild.data;
document.open();
document.close();
document.body.innerHTML = source;
}
/**
* Block js error reporting
*/
function KillError()
{
  return true;
}
window.onerror=KillError;
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