javascript 禁止右键,禁止复制,禁止粘贴

用javascript 禁止右键,禁止复制,禁止粘贴

有时自己辛苦半天做的网页,尤其是一些javascript特效,很容易被人利用查看源文件而复制。那么如何才能防止被人查看源代码呢?我们可以利用event.button特性来做到。下表是event.button属性的可能取值及含义:
0没按键
1按左键
2按右键
3按左和右键
4按中间键
5按左和中间键
6按右和中间键
7按所有的键
参照上表,我们可以在<body>和</body>之间加入如下语句:
<script type="text/javascript">
functionClick(){
if(event.button!=1){alert('XXXXXXX');}
document.οnmοusedοwn=Click;
</script>

<script type="text/javascript">

//以下为禁止鼠标右键的代码,不想禁止的可以删除
<!--

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

functionnocontextmenu()
{
event.cancelBubble=true
event.returnValue=false;

returnfalse;
}

functionnorightclick(e)
{
if(window.Event)
{
if(e.which==2||e.which==3)
returnfalse;
}
else
{if(event.button==2||event.button==3){alert("
xxxxxxxxxxx");}}
{
event.cancelBubble=true
event.returnValue=false;
returnfalse;
}

}

document.οncοntextmenu=nocontextmenu;//forIE5+
document.οnmοusedοwn=norightclick;//forallothers
//-->
</script>

图片禁用鼠标右键代码

<script type="text/javascript">

var clickmessage="本站图片禁用右键!"

function disableclick(e) {

if (document.all) {

if (event.button==2||event.button==3) {

if (event.srcElement.tagName=="IMG"){

alert(clickmessage);

return false;

}

}

}

if (document.layers) {

if (e.which == 2) {

alert(clickmessage);

return false;

}

}

}

function associateimages(){

for(i=0;i<document.images.length;i++)

document.images[i].οnmοusedοwn=disableclick;

}

if (document.all)

document.οnmοusedοwn=disableclick

else if (document.layers)

associateimages()

</script>

功能:禁止右键、禁选择、禁粘贴、禁shift、禁ctrl、禁alt

<scriptlanguage="JavaScript">
<!--
functionkey(){
//禁止Shift
if(event.shiftKey){
window.close();}
//禁止Alt
if(event.altKey){
window.close();}
//禁止Ctrl
if(event.ctrlKey){
window.close();}
returnfalse;}
document.οnkeydοwn=key;
if(window.Event)
document.captureEvents(Event.MOUSEUP);
functionnocontextmenu(){
event.cancelBubble=true
event.returnValue=false;
returnfalse;}
functionnorightclick(e){
if(window.Event){
if(e.which==2||e.which==3)
returnfalse;}
else
if(event.button==2||event.button==3){
event.cancelBubble=true
event.returnValue=false;
returnfalse;}
}
//禁右键
document.οncοntextmenu=nocontextmenu;//forIE5+
document.οnmοusedοwn=norightclick;//forallothers
//-->
</script>

<bodyonselectstart="returnfalse";οnpaste="returnfalse";>

如何用用javascript禁止右键,禁止复制,禁止粘贴,做站时常会用到这些代码:

1. <body οncοntextmenu="window.event.returnValue=false" >将彻底屏蔽鼠标右键特效
<tableborderοncοntextmenu=return(false)><td>no</table>可用于Table

2.<bodyonselectstart="returnfalse">取消选取、防止复制javascript技巧

3.οnpaste="returnfalse"不准粘贴技巧

4.οncοpy="returnfalse;"oncut="returnfalse;"防止复制的javascirpt特效

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值