JS禁止右键、CTRL+C、查看源文件

来源:互联网 发布:c语言 string类 编辑:程序博客网 时间:2024/05/22 13:29

禁用粘贴事件

//禁用ctrl + V 和粘贴$("#input").unbind("paste");//粘贴事件,获取文本框内容$("#input").bind(function(){    var el = $(this);    setTimeout({//获取粘贴文本需setTimeout控制时间        var text = $el.val();        alert(text);    },100);});

禁止ctrl + C

<script type="text/javascript">//禁止ctrl复制document.onkeydown=function(){    if((event.ctrlKey) && (window.event.keycode==67)){          event.returnValue=false;          alert("Ctrl+C被禁止啦!");    }}document.onmousedown=function(){    if(event.button==2){        event.returnValue=false;        alert("右键被禁止啦!");    }}</scription>

//禁止查看源文件function clear(){Source=document.body.firstChild.data;document.open();document.close();document.title=”看不到源代码”;document.body.innerHTML=Source;}</script>//图片下载限制function Click(){if(window.event.srcElement.tagName==”IMG”){alert(‘图片直接右键’);window.event.returnValue=false;}}document.oncontextmenu=Click;<META HTTP-EQUIV=”imagetoolbar” CONTENT=”no”>  插入图片时加入galleryimg属性<img galleryimg=”no” src=””>//禁止右键保存function click() {alert(‘对不起,您不能保存此图片,谢谢您的理解和支持!’) }function click1() {if (event.button==2) {alert(‘对不起,您不能保存此图片,谢谢您的理解和支持!’) }}function CtrlKeyDown(){if (event.ctrlKey) {alert(‘不当的拷贝将损害您的系统!’) }}document.onkeydown=CtrlKeyDown;document.onselectstart=click;document.onmousedown=click1;function   document.onmousedown(){      if(event.button==2||event.button==3)      {            alert( “右健被禁止 “)            return   false        }}
0 0