防止页面内容被选中,无蓝色拖影

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)即可

 

 

 

posted @ 2013-05-19 22:50  winenr123  阅读(215)  评论(0编辑  收藏  举报