阻止页面右键事件

在这里我封装了一个阻止页面右键的函数,目前是初学,可能还不太完善:

<script>
	function addEvent(obj,sEv,fn){
		if(obj.addEventListener){
			obj.addEventListener(sEv,fn,false);
		}else{
			attachEvent('on'+sEv,fn);
		}
	}

	window.onload=function(){
		addEvent(document,'contextmenu',function(ev){
		     var oEvent=ev||event;
		     oEvent.preventDefault && oEvent.preventDefault();
		     return false;
		})
        }
</script>

  

posted @ 2014-11-19 22:03  jinzhu4147  阅读(290)  评论(0编辑  收藏  举报