zoukankan      html  css  js  c++  java
  • 如何在页面屏蔽有些功能,如选择,复制,右键菜单等

    (function(){
        var doc=document,
            ua = navigator.userAgent.toLowerCase(),
            check = function(r){return r.test(ua);},
            isOpera = check(/opera/),
            isChrome = check(/chrome/),
            isWebKit = check(/webkit/),
            isSafari = !isChrome && check(/safari/),
            isSafari2 = isSafari && check(/applewebkit/4/),
            isSafari3 = isSafari && check(/version/3/),
            isSafari4 = isSafari && check(/version/4/),
            isIE = !isOpera && check(/msie/),
            isIE7 = isIE && check(/msie 7/),
            isIE8 = isIE && check(/msie 8/),
            isIE9 = isIE && check(/msie 9/),
            isIE10 = isIE && check(/msie 10/),
            isIE11 = isIE && check(/msie 11/),
            isIE6 = isIE && !isIE7 && !isIE8 && !isIE9 && !isIE10 && !isIE11,
            isGecko = !isWebKit && check(/gecko/),
            isGecko2 = isGecko && check(/rv:1.8/),
            isGecko3 = isGecko && check(/rv:1.9/);
    function preventKey(e) {
    var ev = e || window.event,//获取event对象 obj = ev.target || ev.srcElement,//获取事件源

    t = obj.type || obj.getAttribute('type'),
         readonly = obj.readOnly||obj.getAttribute('readonly'),
         code = ev.keyCode||ev.which||ev.charCode,
         charcode = String.fromCharCode(code).toLowerCase();
         //获取事件源控件类型,控件只读属性,键盘值
    if ( (code == 8 && t != "password" && t != "text" && t != "textarea")||(readonly&&(t == "password" || t == "text" || t == "textarea"))) {
         //除不只读输入框外禁止后退键
                return false;
            }
            if (((isOpera || isGecko)?ev.which==0:true)&&(code == 116 || code == 122|| code == 123 || (ev.shiftKey && code == 121))||(((isOpera || isGecko)?ev.which!=0:true)&&ev.ctrlKey && (charcode == 'a' || charcode == 's'))) {
    //屏蔽 F5,F11,F12,shift+F10,ctrl+a,ctrl+s if (isIE) ev.keyCode = 0; ev.returnValue = false; return false; } };
    if (isOpera || isGecko) doc.onkeypress = preventKey; else if (isIE || isChrome || isSafari) doc.onkeydown = preventKey; if(isIE) document.onselectstart=function(){return false;}; doc.oncontextmenu = function(){ if(window.event){ window.event.cancelBubble = true; window.event.returnValue=false; } return false; }; try{window.history.forward(1);}catch(e){} })();
  • 相关阅读:
    查找数据库表中重复的 Image 类型值
    C#中的引用传递和值传递。
    用JS解决Asp.net Mvc返回JsonResult中DateTime类型数据格式的问题
    根据业务自己设计的.NET工厂模式架构
    封装EF code first用存储过程的分页方法
    2013款MacBook Air装Windows7单系统
    js判断是否在微信浏览器中打开
    EF Code First连接现有数据库
    JS中for循序中延迟加载实现动态效果
    DIV+CSS左右两列自适应高度的方法
  • 原文地址:https://www.cnblogs.com/feixiablog/p/15069212.html
Copyright © 2011-2022 走看看