How JavaScript captures the context menu in the left

Source: Internet
Author: User

Test the click event first. The following is the test code:

var addEvent = document.addEventListener ? function(el,type,fn){      el.addEventListener(type,fn,false);}:function(el,type,fn){     el.attachEvent("on"+type,function(){      fn.call(el,window.event);  });}window.onload = function(){    addEvent(document,"click",function(e){      alert(e.button)   });}window.onload = function(){    addEvent(document.body,"click",function(e){      alert(e.button)   });}
Document Object Element Node
Left Medium Right Left Medium Right
IE8 × ×
Firefox 3.6 × ×
Google Chrome 8.0 × ×
Opera 11.0 × × × ×

Test Results

  1. In the Element Node Section, no difference exists between document. Body, Div, and input [type = button ].
  2. There is no difference in standard mode or weird mode in IE8.
  3. IE8 whether you use the input or button tag to generate a tag, the results are the same
  4. An error occurred while capturing the context menu. It is estimated that it was hijacked by the contextmenu event.

To fully capture the left middle right click, it is estimated that only formal mouse events, such as mousedown, can be used.

Document Object Element Node
Left Medium Right Left Medium Right
IE8
Firefox 3.6
Google Chrome 8.0
Opera 11.0
Related Article

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.