禁止某些事件

 window.onload=function () {
        //禁止缩放
        document.addEventListener('touchstart',function (event) {
            if(event.touches.length>1){
            event.preventDefault();
            }
        });
        var lastTouchEnd=0;
        document.addEventListener('touchend',function (event) {
            var now=(new Date()).getTime();
            if(now-lastTouchEnd<=300){
            event.preventDefault();
            }
            lastTouchEnd=now;
        },false);
        document.addEventListener('gesturestart', function (event) {
            event.preventDefault();
        });
        // 禁止右键菜单
        document.oncontextmenu = function(){ return false; };
        // 禁止文字选择
        document.onselectstart = function(){ return false; };
        // 禁止复制
        document.oncopy = function(){ return false; };
        // 禁止剪切
        document.oncut = function(){ return false; };
        // 禁止粘贴
        document.onpaste = function(){ return false; };
    }

(42 Posts)

Leave a Reply