Javascript determines whether the mouse is left or right-click-compatible with ie, firefox, chrome, and other major browsers

Source: Internet
Author: User

It is very easy to use javascript to determine whether the user clicks the Left or Right button. You only need to add the onmousedown event to the object and use the javascript e. button value to determine whether the user clicks the event. The following is an example.

Document. onmousedown = judgeMouseButton; function judgeMouseButton (e) {var e = window. event | e; // obtain the event object var value = e. button; if (value = 2 | value = 3) {alert ('right-click the click ');} else {alert ('click the left mouse click ');}}
Articles you may be interested in
  • Jquery drop-down menu (ultra-simple and practical, compatible with mainstream browsers such as IE and firefox)
  • Js shields mouse and keyboard events (including right-click, direction key, backspace key, F5 refresh key, etc.), compatible with IE and firefox
  • How to set the DIV layer to display on a flash object, compatible with browsers such as ie and firefox
  • JS checks whether the scroll bar stops scrolling, and is compatible with IE and Firefox browsers.
  • Javascript shield right-click, compatible with IE and firefox
  • Move the mouse over the text to display the floating layer prompt special effects (compatible with all browsers such as IE and Firefox)
  • Javascript to get the current mouse position (compatible with IE and firefox)
  • Js to get the current mouse position, compatible with ie and firefox

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.