如何阻止在我的网站上选择文字?

时间:2014-07-17 16:18:37

标签: javascript internet-explorer textbox textarea

我正在为一家公司的内部网站工作,他们要求我禁用文本选择以及右键单击。他们希望禁用文本选择主要是为了防止人们使用Control + C进行复制,因为禁用了右键单击。

我被要求允许在文本框和文本字段中选择文本。我设法让这个工作,除了在Internet Explorer中用户无法在文本框中选择。 Chrome允许在文本框中选择文字。

<script type="text/JavaScript">
                var msgpopup="This action is disabled.";
                function killCopy(e){
                    return false
                }
                function reEnable(){
                    return true
                }
                document.onselectstart=new Function ("return false")

                if (window.sidebar){
                    document.onmousedown=killCopy
                    document.onclick=reEnable
                }
                function handle(){
                      if(toShowMessage== "1") alert(message);
                      if(closeSelf== "1") self.close();
                      return false;
                }
                function mouseDown() {
                     if (event.button == "2" || event.button == "3"){handle();}
                }
                function mouseUp(e) {
                     if (e.which == "2" || e.which == "3"){ handle();}
                }
                document.onmousedown=mouseDown;
                document.onmouseup=mouseUp;
                document.oncontextmenu=new Function("alert(msgpopup);return false")
            </script>
            <script type="text/javascript">
                function right(e) { 
                    if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2)) 
                        return false; 
                    else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) { 
                        return false;
                    }
                    return true; 
                    } 
                    document.onmousedown=right; 
                    if (document.layers) window.captureEvents(Event.MOUSEDOWN); window.onmousedown=right; 
            </script>

感谢。

0 个答案:

没有答案
相关问题