屏蔽浏览器默认的右击事件

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/weixin_40578880/article/details/102758586
//方法一 
document.oncontextmenu = function(){         
    return false;
};
//方法二  不支持 IE < 9   
window.addEventListener('contextmenu', function(e){ 
	e.preventDefault();
}, false);

通常输入框不禁用

document.oncontextmenu = function (event){   
   if(window.event){   
    event = window.event;   
   }   

   try{   
    let the = event.srcElement;       
    if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){     
      return false;       
    }     
      return true;   
    } catch (e){       
      return false;   
   }
}

猜你喜欢

转载自blog.csdn.net/weixin_40578880/article/details/102758586