美文网首页
前端css js 不允许页面选择复制选择的两种方法

前端css js 不允许页面选择复制选择的两种方法

作者: 雪河冰兰 | 来源:发表于2018-05-02 14:22 被阅读32次

    有关不允许页面选择复制的几种方法

    1 JS方法

    • 以下方法我发现把左键选择 右键都控制了,刚一点击,就执行这个函数了
    $(document.body).bind("selectstart", function(){
        return false;
    });
    

    2 css方法

    http://www.divcss5.com/rumen/r17062.shtml

    
    .noselect {
    -webkit-touch-callout: none; /* iOS Safari */
    -webkit-user-select: none; /* Chrome/Safari/Opera */
    -khtml-user-select: none; /* Konqueror */
    -moz-user-select: none; /* Firefox */
    -ms-user-select: none; /* Internet Explorer/Edge */
    user-select: none; /* Non-prefixed version, currently not supported by any browser */
    }
    

    -在 IE < 10 和Opera < 15中我们需要在需要禁止选中的元素上面添加一个属性

    unselectable="on",否则可能不会生效哦~不过现代浏览器如果不是非得兼容一些老的浏览器也可以不加。

    相关文章

      网友评论

          本文标题:前端css js 不允许页面选择复制选择的两种方法

          本文链接:https://www.haomeiwen.com/subject/hchcrftx.html