Live Chat Icon For mobile
Live Chat Icon

How can I check whether left or right mouse button has been clicked?

Platform: ASP.NET| Category: Client Side Scripting

To determine whether the user clicked the left or right button, you can use the following properties.

  • Event.which in Netscape Navigator
  • event.button in Internet Explorer

If the value of these properties is 1, the event occurred for the left button. In the following example, the onMouseDown event handler displays the messages Left button or Right button, depending on the mouse button you actually have clicked. The messages will appear on your browser’s status bar. Click or right-click anywhere on this page to see it work:

		<script language='JavaScript'>
		function mouseDown(e) 
			 if (parseInt(navigator.appVersion)>3)
				var clickType=1;
			  	if (navigator.appName=='Netscape') clickType=e.which;
				else clickType=event.button;
				if (clickType==1) 
					self.status=’Left button!’;
					alert('Left Button');
			                if (clickType!=1)
			  		self.status=’Right button!’;
					alert('Right Button');
		 return true;
		if (parseInt(navigator.appVersion)>3)
			 document.onmousedown = mouseDown;
			 if (navigator.appName=='Netscape') 

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.