How to disable right click in JavaScript

{0 Comments}

We have already written a script to disable copy and paste in the browser. Which also disable right click of the browser too so you can use the same JavaScript to disable right click which is as follows 

 Javascript |  copy code |? 
01
 <script language="javascript"> 
02
function click() { 
03
return false;} 
04
function click1(){if (event.button==2) {return false; }} 
05
function CtrlKeyDown(){ 
06
if (event.keyCode==67&&event.ctrlKey) 
07
{ 
08
  clipboardData.setData('text',''); 
09
  return false;  
10
} 
11
} 
12
document.onkeydown=CtrlKeyDown; 
13
document.onselectstart=click; 
14
document.onmousedown=click1; 
15
    </script>
16
&nbsp;
17
    <noscript>
18
        <iframe src="*.html"></iframe>
19
    </noscript>
20
&nbsp;
21
    <script language="javascript">  
22
<!--  
23
if (window.Event)  
24
document.captureEvents(Event.MOUSEUP);  
25
function nocontextmenu(){  
26
event.cancelBubble = true  
27
event.returnValue = false;  
28
return false;  
29
}  
30
function norightclick(e){  
31
if (window.Event){ 
32
if (e.which == 2 || e.which == 3) 
33
return false; 
34
}  
35
else if (event.button == 2 || event.button == 3) 
36
{ 
37
event.cancelBubble = true; 
38
event.returnValue = false;return false;}  
39
}  
40
document.oncontextmenu = nocontextmenu; // for IE5+  
41
document.onmousedown = norightclick; // for all others  
42
//--></script>
43

Leave a Comment

Your email address will not be published.