What is the correct JavaScript syntax to disable right mouse click on your web page?
Explanation
The buttons being pressed when the mouse event was fired:
  • Left button=1, Right button=2, Middle (wheel) button=4, 4th button (typically, "Browser Back" button)=8, 5th button (typically, "Browser Forward" button)=16.
  • If two or more buttons are pressed, returns the logical sum of the values.
  • E.g., if Left button and Right button are pressed, returns 3 (=1 | 2).

function disableclick(event)
{
  if(event.button==2)
   {
     return false;	
   }
}

@misterds thanks! updated the explanation

2018 Jan 30, 5:55:38 PM

The buttons being pressed when the mouse event was fired: Left button=1, Right button=2, Middle (wheel) button=4, 4th button (typically, "Browser Back" button)=8, 5th button (typically, "Browser Forward" button)=16. If two or more buttons are pressed, returns the logical sum of the values. E.g., if Left button and Right button are pressed, returns 3 (=1 | 2). More info.

2017 Dec 15, 6:22:18 PM

@vitaliiS Thanks! Fixed

2017 May 18, 12:00:50 AM

In explanation we see that function has a parameter "e", but in if operator we use "event". Is it okay?

2017 Feb 5, 9:46:18 PM

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes