禁止鼠标右键的代码(转)

1.禁止鼠标左右键代码/禁止网页选中/禁止另存为/防复制代码

<body οncοntextmenu="return false" onselectstart="return false">
<noscript><iframe src="/*.html>";</iframe></noscript>
<script>
function stop(){
return false;
}
document.οncοntextmenu=stop;
</script>

2.禁止鼠标左右键

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

3.禁止选中代码

<SCRIPT language=JavaScript>
document.οncοntextmenu=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.οnmοusedοwn=disableselect
document.οnmοuseup=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.οnmοusedοwn=disableselect
document.οnmοuseup=reEnable
}
</script>

9.禁用右键

<script>
function stop(){
return false;
}
document.οncοntextmenu=stop;
</script>

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>


=================2013-11-28=================

OnContextMenu事件

用oncontextmenu事件单禁用右键菜单 
一个页面中,BODY中用οncοntextmenu='return false'来取消鼠标右键;

在JS中设置οncοntextmenu='return true'用window.document.oncontextmenu = function(){ return false;} 

onconTextmenu=window.event.returnValue=false;右键菜单禁用,用这个可以禁止复制。 

在<body>中加入属性代码: 


οncοntextmenu="return false"       
onselectstart="return false"                   禁止选中网页上的内容 
οncοpy="return false"                           防复制用户在网页上选中的内容 


防止用户另存网页: 
利用<noscript><iframe src=*.html></iframe></noscript>标签,能防止网页的直接另存,但不能防止网页被人使用工具下载 *为通配符。 
例1: 
<html> 
<head> 
<title>OnContextMenu事件</title> 
<script language="JavaScript"> 
<!-- 
function uFunction() 
{     document.all.infoDiv.innerHTML='你按下了鼠标右键,但是右键菜单不能 显示!';} 
function uFunction2() 
{    document.all.infoDiv.innerHTML='你按下了Ctrl+鼠标右键,可以 显示右键菜单。';} 
//--> 
</script> 
</head> 
<body οncοntextmenu="if(!event.ctrlKey){uFunction();return false}else{uFunction2()}"> 
<div id="infoDiv">你按下了鼠标右键,但是右键菜单不能 显示!<br>你按下了Ctrl+鼠标右键,可以显示右键菜单。 
</div></body> 
</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值