1种方式:
实现原理是,在<body>语法标签里加入如下代码:
ondragstart="window.event.returnValue=false;" oncontextmenu="window.event.returnValue=false;" onselectstart="event.returnValue=false;"
这里,鼠标拖曳(ondragstart)、选择(onselectstart)和右键弹出pop菜单。
2种方式:
在引用js文件中加入
document.oncontextmenu=function(){
return false;
};
document.ondragstart=function(){
return false;
};
document.onselectstart=function(){
return false;};
document.onbeforecopy=function(){
return false;};
document.onselect=function(){
document.selection.empty();
};
document.oncopy=function(){
document.selection.empty();
};
document.onmouseup=function(){
document.selection.empty();
};
3.屏蔽F5键刷新
<script>
function DisableF5(){
with (event){
// F5 and Ctrl+R
if (keyCode==116 || (ctrlKey && keyCode==82)){
event.keyCode = 0;
event.cancelBubble = true;
return false;
}
}
}
document.onkeydown = DisableF5;
</script>
实现原理是,在<body>语法标签里加入如下代码:
ondragstart="window.event.returnValue=false;" oncontextmenu="window.event.returnValue=false;" onselectstart="event.returnValue=false;"
这里,鼠标拖曳(ondragstart)、选择(onselectstart)和右键弹出pop菜单。
2种方式:
在引用js文件中加入
document.oncontextmenu=function(){
return false;
};
document.ondragstart=function(){
return false;
};
document.onselectstart=function(){
return false;};
document.onbeforecopy=function(){
return false;};
document.onselect=function(){
document.selection.empty();
};
document.oncopy=function(){
document.selection.empty();
};
document.onmouseup=function(){
document.selection.empty();
};
3.屏蔽F5键刷新
<script>
function DisableF5(){
with (event){
// F5 and Ctrl+R
if (keyCode==116 || (ctrlKey && keyCode==82)){
event.keyCode = 0;
event.cancelBubble = true;
return false;
}
}
}
document.onkeydown = DisableF5;
</script>
本文介绍了一种禁用网页上的鼠标右键菜单、拖拽、选中文本以及F5刷新功能的方法。通过在HTML <body> 标签内加入特定的JavaScript代码,可以有效防止用户进行上述操作。这对于保护网站内容不被轻易复制有一定作用。
138

被折叠的 条评论
为什么被折叠?



