1. 程式人生 > >javascript 實現禁止右鍵,複製,選取文字 (相容firefox,IE,chrome等主流瀏覽器)...

javascript 實現禁止右鍵,複製,選取文字 (相容firefox,IE,chrome等主流瀏覽器)...

或者:
body{
    -webkit-touch-callout: none;  
	-webkit-user-select: none;  
	-khtml-user-select: none;  
	-moz-user-select: none;  
	-ms-user-select: none;  
	user-select: none;  
}

function iEsc(){ return false; }
function iRec(){ return true; }
function DisableKeys() {
	if(event.ctrlKey || event.shiftKey || event.altKey)  {
	window.event.returnValue=false;
	iEsc();}
}

document.ondragstart=iEsc;
document.onkeydown=DisableKeys;
document.oncontextmenu=iEsc;

if (typeof document.onselectstart !="undefined") document.onselectstart=iEsc;
else
{
	document.onmousedown=iEsc;
	document.onmouseup=iRec;
}

function DisableRightClick(e)
{
	if (window.Event){ if (e.which == 2 || e.which == 3) iEsc();}
	else
		if (event.button == 2 || event.button == 3)
		{
			event.cancelBubble = true
			event.returnValue = false;
			iEsc();
		}
}