css和js禁止网页选择文字

user-select有两个值:

none:用户不能选择文本

text:用户可以选择文本

需要注意的是:user-select并不是一个W3C的CSS标准属性,浏览器支持的不完整,需要对每种浏览器进行调整

<style>
    body{
        -moz-user-select: none;             /*火狐*/
        -webkit-user-select: none;          /*webkit浏览器*/
        -ms-user-select: none;              /*IE10*/
        -khtml-user-select: none;           /*早期浏览器*/
        user-select: none;
    }
    /*IE6-9还没发现相关的CSS属性*/
    /*IE6-9*/
    document.body.onselectstart = document.body.ondrag = function(){
        return false;
    }
</style>
原文地址:https://www.cnblogs.com/phpfensi/p/3852698.html