• 禁止选择文本和禁用右键 v1.0


    var zhonghao={
        //绑定事件
        myAddEvent: function(obj, sEvent, fn){if(obj.attachEvent){obj.attachEvent('on'+sEvent, fn);}else{obj.addEventListener(sEvent, fn, false);}},
        //禁止选择文本
        disableselect:function(e){
            var omitformtags=["input", "textarea", "select"]
            omitformtags=omitformtags.join("|")
            if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1) 
            return false 
        },
        reEnable:function(){ 
            return true 
        },
    
        //禁用右键 
    
        stop:function(){ 
        return false; 
    
        }    
    
    }
    
    zhonghao.myAddEvent(window,"load",function(){
    
        //禁止选择文本
    
        if (typeof document.onselectstart!="undefined") 
            document.onselectstart=new Function ("return false");
        else{ 
            document.onmousedown=zhonghao.disableselect ;
            document.onmouseup=zhonghao.reEnable ;
        }
    
    
        //禁止右键
    
        document.oncontextmenu=zhonghao.stop;
    })
    <script> function stop() {
        return false };
    document.oncontextmenu = stop;
    javascript: ; </script>
    function disableselect(e) {
        var omitformtags = ["input", "textarea", "select"];
        omitformtags = omitformtags.join("|");
        if (omitformtags.indexOf(e.target.tagName.toLowerCase()) == -1);
        return false
    };
    
    function reEnable() {
        return true
    };
    if (typeof document.onselectstart != "undefined") document.onselectstart = new Function("return false");
    else {
        document.onmousedown = disableselect();
        document.onmouseup = reEnable()
    }
    转载请注明出处: 欢迎留言或qq(1090413588)交流
  • 相关阅读:
    Mysql基础知识:操作数据库
    Mysql基础知识:数据类型
    Struts2下载与使用
    Open Live Writer安装使用
    博客园界面设置
    (3)break、continue
    (2)基础语法
    查找五:散列表查找
    查找三:平衡二叉树
    centos 安装 masscan
  • 原文地址:https://www.cnblogs.com/linyusong/p/6406658.html
Copyright © 2020-2023  润新知