2013-02-02 27 views
0

我有下面的代碼來禁用右鍵單擊。當你點擊右鍵時,說功能被禁用。哪些工作,但我希望它沒有顯示任何基本上,當你點擊右鍵沒有任何反應......我們可以用什麼樣的魔法來做到這一點?禁用在網站的右鍵點擊

var message="Function Disabled!"; function clickIE4(){ 
if (event.button==2){ alert(message); return false; } } 
function clickNS4(e){ 
if (document.layers||document.getElementById&&!document.all){ 
if (e.which==2||e.which==3){ alert(message); return false; } } } 
if (document.layers){ document.captureEvents(Event.MOUSEDOWN); document.onmousedown=clickNS4; } 
else if (document.all&&!document.getElementById){ document.onmousedown=clickIE4; } document.oncontextmenu=new Function("alert(message);return false") 
+0

的Java = JavaScript的 – Doorknob

+2

java的是JavaScript作爲汽車地毯 – AlienWebguy

+0

你意識到人可以直接關閉JS,然後右鍵單擊所有他們想要, 對?或加載開發人員工具並禁用您的事件處理程序?這基本上只是一個小小的麻煩。 – R0MANARMY

回答

2

只需刪除警報:

if (event.button==2){ return false; } } 
-1
## How To Disable Right Click with Out Display any thing or Var Massage ## 
<script language=JavaScript> 
<!-- 
var message=""; 
function clickIE4() 
function clickNS4(e){ 
if (document.layers||document.getElementById&&!document.all){ 
if (e.which==2||e.which==3){ 
alert(message); 
return false; 
} 
} 
} 

if (document.layers){ 
document.captureEvents(Event.MOUSEDOWN); 
document.onmousedown=clickNS4; 
} 
else if (document.all&&!document.getElementById){ 
document.onmousedown=clickIE4; 
} 

document.oncontextmenu=new Function("alert(message);return false") 

// --> 
</script> 
+1

這是錯誤的,不好的做法(「腳本語言= JavaScript「),僅用於代碼,甚至不能(!)回答這個問題。語法也是錯誤的。 –

+1

嗨林奧林你我不這麼認爲告訴KG的放在和上面的代碼只是在任何HTML嘗試它,並感覺不同 –

+1

你真的測試過或讀過這個問題嗎?你的代碼仍然有一個'alert()'調用。再次閱讀問題和您的代碼。 –