禁止鼠标各种操作的代码

来源:互联网 发布:网络语言的特点 编辑:程序博客网 时间:2024/05/20 18:52

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;}

原创粉丝点击