zoukankan      html  css  js  c++  java
  • 防止页面内容被选中,无蓝色拖影

    document.onselectstart=function(){

      return false;

    }

    今天在网上查了下,每种浏览器都有特定的解决方法

    以上是chrome,IE9能支持。

    addEventlistener不能使用selectstart,不知道为何,有时间找下为什么不能绑定。。

    body.setAttribute("style","-moz-user-select:none")

    上面为FF,FF是通过设置自有的css属性-moz-user-select:none 是其不能被选中

    综合IE9,CHROME,FF

            function clearSelect(b) {
                var body = document.getElementsByTagName("body")[0];
                if (b) {
                    body.onselectstart = function () { //IE,CHOMRE
                        return false;
                    }
                    document.unselectable = "on";
                    body.setAttribute("style", "-moz-user-select:none"); //FF
                    
                } else {
                    body.onselectstart = function () { }
                    body.setAttribute("style", "-moz-user-select:''"); //FF
                }
            }

    例如在移动网页元素的时候,mouseDown时候使用clearSelect(true);mouseUp时候使用clearSelect(false)即可

  • 相关阅读:
    Got05
    Git07
    Git09
    Git11
    Git10
    Git13
    Git12
    Git14
    Listview点击跳转页面
    《三个和尚》观后感
  • 原文地址:https://www.cnblogs.com/strangerqt/p/3087771.html
Copyright © 2011-2022 走看看