您的位置:首页 > 编程语言

禁止鼠标各种操作的代码

2012-09-05 14:03 423 查看
document.onselectstart =function() {return false;} // 防选择

document.oncopy =function() {return false;} // 防复制

document.oncut =function() {return false;} // 防剪贴

document.onbeforecopy =function() {return false;}

document.ondragstart =function() {return false;} //防拖动

document.oncontextmenu =function() {return false;} //防右键

document.onmouseup =function() {document.selection.empty();}

document.onselect =function() {document.selection.empty();}

document.oncopy =function() {document.selection.empty();}

document.onmousedown =function() {if (event.button!==1){alert('禁止操作');}}

document.onkeydown =function() {alert("禁止操作");event.keyCode=0;event.returnValue=false;}

// 屏蔽PrintScreen

function testclip(){

try {

if(clipboardData.getData("Text")||clipboardData.getData("HTML")||clipboardData.getData("URL")) //检测系统内存

{

null; //不为图像则保留内存

}

}

catch(e){

clipboardData.setData("Text","")//清空内存

}

setTimeout("testclip()",500)

}

testclip();//不停清空剪贴板

// 禁止打印

@media print{

body{display:none}

}

// 禁止保存

<noscript>

<iframe src="*.htm"></iframe>

</noscript>

// 禁用右键

function nocontextmenu(){

event.cancelBubble = true

event.returnValue = false;

return false;

}

function norightclick(e){

if (window.Event){

if (e.which == 2 || e.which == 3)

return false;

}else if (event.button == 2 || event.button == 3){

event.cancelBubble = true;

event.returnValue = false;

return false;

}

}

//禁止右键

document.oncontextmenu=nocontextmenu; // for IE5+

document.onmousedown=norightclick; // for all others

禁用

window.ClearEvent=function(){event.cancelBubble=false;

var sSrcTagName=event.srcElement.tagName.toLowerCase();

return (sSrcTagName=="textarea" || sSrcTagName=="input" || sSrcTagName=="select");}

window.ClearKey=function(){event.cancelBubble=false;var iKeyCode=event.keyCode;return !(iKeyCode==78 && event.ctrlKey);}

with (window.document){oncontextmenu=onselectstart=ondragstart=window.ClearEvent;onkeydown=window.ClearKey;}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: