This is a discussion on Mouse Events within the HTML, CSS and Javascript Coding Techniques forums, part of the Web Development category; Hi all.... Can anyone discuss briefly about the javascript mouse events. Thanks & Regards P.vinothkumar...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi all... The click event occurs for the left mouse button only. Therefore, onClick event handlers do not need to preform the left-versus-right button test. On the other hand, the mousedown and mouseup events may occur for any mouse button. To determine whether the user clicked the left or right button, you can use the following event 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!'; if (clickType!=1) self.status='Right button!'; } return true; } if (parseInt(navigator.appVersion)>3) { document.onmousedown = mouseDown; if (navigator.appName=="Netscape") document.captureEvents(Event.MOUSEDOWN); } </script> Thanks... |
| |||
| Hi all... How can I disable the Windows context menu that normally shows up when the user clicks the right mouse button? In most modern browsers, you can disable the context menu by using the oncontextmenu event handler in the body tag of your page: <body oncontextmenu="return false;"> Try right-clicking anywhere on this page - the context menu won't show up! In older browsers (beginning with Netscape Navigator 4.x and Internet Explorer 4.x) you can disable the right-button menu by displaying an alert message on right-click. To do so, insert the following code in your page's <HEAD> section: <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) { alert ('Right mouse button is disabled.') return false; } } return true; } if (parseInt(navigator.appVersion)>3) { document.onmousedown = mouseDown; if (navigator.appName=="Netscape") document.captureEvents(Event.MOUSEDOWN); } </script> Thanks.... |
| |||
| Hi all... <script language="JavaScript"> function mouseDown(e) { var ctrlPressed=0; var altPressed=0; var shiftPressed=0; if (parseInt(navigator.appVersion)>3) { var evt = navigator.appName=="Netscape" ? e:event; if (navigator.appName=="Netscape" && parseInt(navigator.appVersion)==4) { // NETSCAPE 4 CODE var mString =(e.modifiers+32).toString(2).substring(3,6); shiftPressed=(mString.charAt(0)=="1"); ctrlPressed =(mString.charAt(1)=="1"); altPressed =(mString.charAt(2)=="1"); self.status="modifiers="+e.modifiers+" ("+mString+")" } else { // NEWER BROWSERS [CROSS-PLATFORM] shiftPressed=evt.shiftKey; altPressed =evt.altKey; ctrlPressed =evt.ctrlKey; self.status="" + "shiftKey="+shiftPressed +", altKey=" +altPressed +", ctrlKey=" +ctrlPressed } if (shiftPressed || altPressed || ctrlPressed) alert ("Mouse clicked with the following keys:\n" + (shiftPressed ? "Shift ":"") + (altPressed ? "Alt " :"") + (ctrlPressed ? "Ctrl " :"") ) } return true; } if (parseInt(navigator.appVersion)>3) { document.onmousedown = mouseDown; if (navigator.appName=="Netscape") document.captureEvents(Event.MOUSEDOWN); } </script> Thanks.... |
| |||
| Hi all.... <script language="JavaScript"> function mouseDown(e) { var shiftPressed=0; if (parseInt(navigator.appVersion)>3) { if (navigator.appName=="Netscape") shiftPressed=(e.modifiers-0>3); else shiftPressed=event.shiftKey; if (shiftPressed) { alert ('Shift-click is disabled.') return false; } } return true; } if (parseInt(navigator.appVersion)>3) { document.onmousedown = mouseDown; if (navigator.appName=="Netscape") document.captureEvents(Event.MOUSEDOWN); } <script> Thanks... |
| |||
| Hi all.... How can I disable the right-click context menu for a particular image, while still enabling the menu for all other parts of my page? Yes. In most modern browsers you can disable the right-click menu for a particular image. To do so, you can use the event handler oncontextmenu="return false;" within the IMG tag that defines your image: <IMG border=0 src="..." oncontextmenu="return false;"> Thanks.... |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using javascript how to show tooltip while mouse over ? | sathian | HTML, CSS and Javascript Coding Techniques | 1 | 11-16-2007 04:31 AM |
| Windows Forms Mouse Handling | Sundaram | C# Programming | 3 | 09-25-2007 08:51 AM |
| How do I detect mouse events with Ctrl, Alt, and Shift keys? | itbarota | HTML, CSS and Javascript Coding Techniques | 2 | 09-18-2007 10:49 PM |
| Mouse event | varghese | HTML, CSS and Javascript Coding Techniques | 1 | 09-18-2007 08:31 AM |
| How can I detect mouse events with Ctrl, Alt, and Shift keys? | kingmaker | HTML, CSS and Javascript Coding Techniques | 1 | 08-10-2007 03:33 AM |