js 屏蔽浏览器右键菜单

<script type="text/javascript">  
    function doNothing(){  
        window.event.returnValue=false;  
        return false;  
    }  
</script>  
   <body oncontextmenu="doNothing()">  

有时候我们在某些网站上不想用户点击右键进行复制等操作

在body里面处理下就好了

移动端长按会复制等选项可以使用下述的代码屏蔽这个功能,将下述的css加到代码中即可

/*在手机浏览器中,长按可选中文本,但如果在应用中,会给人一种异样的感觉,最好还是禁用此功能为上*/  
* {  
-webkit-touch-callout:none;  
-webkit-user-select:none;  
-khtml-user-select:none;  
-moz-user-select:none;  
-ms-user-select:none;  
user-select:none;  
}  

js代码-效果:防止复制+禁止右键兼容主流浏览器

很多时候我们自己网站上的原创文章不希望被别人直接复制拷贝走

下面我就给大家介绍一个JS,可以实现:防止复制+禁止右键的效果

并且兼容目前的各个浏览器。

话不多说,直接上代码。

body {
-moz-user-select : none;
-webkit-user-select: none;
}
function iEsc(){ return false; }
function iRec(){ return true; }
function DisableKeys() {
if(event.ctrlKey || event.shiftKey || event.altKey)  {
window.event.returnValue=false;
iEsc();}
}
document.ondragstart=iEsc;
document.onkeydown=DisableKeys;
document.oncontextmenu=iEsc;
if (typeof document.onselectstart !="undefined")
document.onselectstart=iEsc;
else{//qsyz.net
document.onmousedown=iEsc;
document.onmouseup=iRec;
}
function DisableRightClick(www_qsyz_net){
if (window.Event){
if (www_qsyz_net.which == 2 || www_qsyz_net.which == 3)
iEsc();}
else
if (event.button == 2 || event.button == 3){
event.cancelBubble = true
event.returnValue = false;
iEsc();}
}
原文地址:https://www.cnblogs.com/jiangxiaobo/p/6273578.html