禁用右键菜单
oncontextmenu事件禁用右键菜单
document.oncontextmenu = function(){
event.returnValue = false;
}
//或者直接返回整个事件
document.oncontextmenu = function(){
return false;
}
或者:body中加入如下的代码,鼠标的左右键都失效
topmargin="0"
οncοntextmenu="return false" οndragstart="return false" onselectstart
="return false" οnselect="document.selection.empty()"
οncοpy="document.selection.empty()" onbeforecopy="return false"
οnmοuseup="document.selection.empty()"
禁用选取内容
onselectstart事件禁用网页上选取的内容
document.onselectstart = function(){
event.returnValue = false;
}
//或者直接返回整个事件
document.onselectstart = function(){
return false;
}
禁用复制
oncopy事件禁用复制
document.oncopy = function(){
event.returnValue = false;
}
// 或者直接返回整个事件
document.oncopy = function(){
return false;
}
以上三种事件,如果只想单纯的禁用鼠标右键,和复制粘贴,还可以将它们直接写到HTML中的body上面
<body oncontextmenu = "return false" ></body>
<body onselectstart = "return false" ></body>
<body oncopy = "return false" ></body>
或者:禁止网页内容复制.粘贴:在body中加入以下代码
<body
οnmοusemοve=/HideMenu()/ οncοntextmenu="return false"
οndragstart="return false" onselectstart ="return false"
οnselect="document.selection.empty()"
οncοpy="document.selection.empty()" onbeforecopy="return false"
οnmοuseup="document.selection.empty()">
禁用鼠标事件
document.onmousedown = function(e){
if ( e.which == 2 ){// 鼠标滚轮的按下,滚动不触发
return false;
}
if( e.which==3 ){// 鼠标右键
return false;
}
}
禁用键盘中的ctrl、alt、shift
document.onkeydown = function(){
if( event.ctrlKey ){
return false;
}
if ( event.altKey ){
return false;
}
if ( event.shiftKey ){
return false;
}
}
禁用F12事件
/*document.oncontextmenu = function(){return false;}*/
document.onkeydown=function (e){
var currKey=0,evt=e||window.event;
currKey=evt.keyCode||evt.which||evt.charCode;
if (currKey == 123) {
window.event.cancelBubble = true;
window.event.returnValue = false;
}
}
禁止网页另存为
在body后面加入以下代码
<noscript>
<iframe src="*.htm"></iframe>
</noscript>