您的位置:首页 > Web前端 > JavaScript

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

2017-02-09 22:51 246 查看

禁用粘贴事件

//禁用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
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  javascript