菜心哥 发表于 2021-11-5 21:34:47

网页中禁止右键 查看 复制代码

1、禁止鼠标左右键<SCRIPT language=javascript>
<!--
if (window.Event)
document.captureEvents(Event.MOUSEUP);
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
18 event.returnValue = false;
19 return false;
}
}
document.oncontextmenu = nocontextmenu; // for IE5+
document.onmousedown = norightclick; // for all others
//-->
</SCRIPT>2、禁止鼠标左右键代码/禁止网页选中/禁止另存为/防复制代码
<body oncontextmenu="return false" onselectstart="return false">
<noscript><iframe src="/*.html>";</iframe></noscript>
<script>
function stop(){
return false;
}
document.oncontextmenu=stop;
</script>3、禁止选中代码
<SCRIPT language=JavaScript>
document.oncontextmenu=new Function("event.returnValue=false;");
document.onselectstart=new Function("event.returnValue=false;");
</SCRIPT>4、禁止另存为
<noscript>
<iframe src="/*.htm"></iframe>
</noscript>5、防拷贝/复制代码
<body leftmargin=0 topmargin=0 >6、禁止选择文本
<script type="text/javascript">
var omitformtags=["input", "textarea", "select"]
omitformtagsomitformtags=omitformtags.join("|")
function disableselect(e){
if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1)
return false
}
function reEnable(){
return true
}
if (typeof document.onselectstart!="undefined")
document.onselectstart=new Function ("return false")
else{
document.onmousedown=disableselect
document.onmouseup=reEnable
}
</script>7、禁止网页另存为
<noscript><iframe src="/*.html>";</iframe></noscript>8、禁止选择文本
<script type="text/javascript">

var omitformtags=["input", "textarea", "select"]

omitformtagsomitformtags=omitformtags.join("|")

function disableselect(e){
if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1)
return false
}

function reEnable(){
return true
}

if (typeof document.onselectstart!="undefined")
document.onselectstart=new Function ("return false")
else{
document.onmousedown=disableselect
document.onmouseup=reEnable
}
</script>9、禁用右键
<script>
function stop(){
return false;
}
document.oncontextmenu=stop;
</script>或者在<body>里加上
10、真正的鼠标右键屏蔽
<script language="JavaScript">
<!--

if (window.Event)
document.captureEvents(Event.MOUSEUP);

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
//-->
</script>反之要取消也是找到以上相关代码取消就行了




放置说明:以上代码按需要来使用,比如只想用一个禁止右键的,就选一个可以禁止右键的就可以,不用全部放到文件里。
首先复制上面你需要用到的代码,放到你想要用到的页面(比如我只想门户首页里禁止右键,那就把这代码放到模板文件夹里的portal/index.php或index.htm里的最底部),一般是希望全站都有这功能,那就把代码放到公共的底部文件里:模板文件夹里的common/footer.php或footer.htm文件的最底部里。

页: [1]
查看完整版本: 网页中禁止右键 查看 复制代码