您现在的位置:首页 >> 前端 >> 内容

阻止文章被别人复制粘贴的代码方法

时间:2018/2/11 14:17:18 点击:

  核心提示:直接在body 里加上这一段代码body onmousemove=/HideMenu()/ oncontextmenu=return falseondragstart=return false ons...

直接在body 里加上这一段代码

<body onmousemove=/HideMenu()/ oncontextmenu="return false"
ondragstart="return false" onselectstart ="return false" 
onselect="document.selection.empty()" 
oncopy="document.selection.empty()" onbeforecopy="return false" 
onmouseup="document.selection.empty()">

禁用键盘中的ctrl、alt、shift复制黏贴

document.onkeydown = function(){
    if( event.ctrlKey ){
        return false;
    }
    if ( event.altKey ){
        return false;
    }
    if ( event.shiftKey ){
        return false;
    }
}
禁用鼠标事件
document.onmousedown = function(e){
    if ( e.which == 2 ){// 鼠标滚轮的按下,滚动不触发
        return false;
    }
    if( e.which==3 ){// 鼠标右键
        return false;
    }
}

如果只想单纯的禁用鼠标右键,和复制粘贴,还可以将它们直接写到HTML中的body上面;

<body oncontextmenu = "return false" ></body>

<body onselectstart = "return false" ></body>

<body oncopy = "return false" ></body>

作者:网络 来源:陌路繁华,各安天涯