实现网页中的文字不允许被复制

两种方法:

第一种、CSS

body{
    -moz-user-select:none; /* Firefox私有属性 */
    -webkit-user-select:none; /* WebKit内核私有属性 */
    -ms-user-select:none; /* IE私有属性(IE10及以后) */
    -khtml-user-select:none; /* KHTML内核私有属性 */
    -o-user-select:none; /* Opera私有属性 */
    user-select:none; /* CSS3属性 */
}

第二种、JS

document.body.onselectstart = document.body.ondrag = function(){
    return false;
}

注意:一些旧版浏览器(比如IE6-IE9),没有相关的CSS属性,我们必须用第二种方式来解决。

猜你喜欢

转载自blog.csdn.net/kukudelaomao/article/details/81082367