凌的博客

您现在的位置是: 首页 > 前端学习 > Js > 

Js

js禁用右键点击

2016-12-26 Js 1024
很实用的javascript: function no_right(e){ if(!document.rightClickDisabled){ if(document.layers){ document.captureEvents(Event.MOUSEDOWN); document.onmousedown = disableRightClick; }else{ document.oncontextmenu = disableRightClick; }

很实用的javascript:

function no_right(e){
	if(!document.rightClickDisabled){
		if(document.layers){
			document.captureEvents(Event.MOUSEDOWN);
			document.onmousedown = disableRightClick;
		}else{
			document.oncontextmenu = disableRightClick;
		}
		return document.rightClickDisabled = true;
	}
	
	if(document.layers || (document.getElementById && !document.all)){
		if (e.which==2||e.which==3) return false;
	}else{
		return false;
	}
}
no_right();

文章评论

0条评论