title: How to prevent default behavior when middle click on a link (browsers' extensions)
body: <p>In my Firefox's &amp; Google Chrome's extensions I can prevent default behavior when middle click on a link like this:</p>
  
  <pre><code>function onClick(e) {
      var url = getLink(e);
      if (e.button == 1) { // Middle Click
          // prevent opening a link
          e.preventDefault();
          e.stopPropagation();
          // do something with a link
          // url ...
      }
  }
  if (browser == "chrome")
      document.addEventListener("auxclick", onClick); // for Google Chrome (old "click" event doesn't prevent opening link with middle click but they added "auxclick" for this)
  else if (browser == "firefox") 
      document.addEventListener("click", onClick); // for Firefox (still works)
  </code></pre>
  
  <p>also <a href="https://developers.google.com/web/updates/2016/10/auxclick" rel="nofollow noreferrer">https://developers.google.com/web/updates/2016/10/auxclick</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/Events/auxclick" rel="nofollow noreferrer">https://developer.mozilla.org/en-US/docs/Web/Events/auxclick</a></p>
  
  <p>I'm also trying to do this for my Microsoft Edge's extension, but seems middle click event for this browser doesn't work at all:</p>
  
  <pre><code>function onClick(e) {
      var url = getLink(e);
      if (e.button == 1) { // Middle Click
          alert("hello"); // isn't working for Microsoft Edge
      }
  }
  document.addEventListener("click", onClick);
  </code></pre>
  
  <p>So instead of this for Microsoft Edge I use:</p>
  
  <pre><code>document.addEventListener("mousedown", function(e) {
      var target = e.target || e.srcElement;
      while (target) {
          if (target instanceof HTMLAnchorElement)
              break;
          target = target.parentNode;
      }
      if (e.button == 1 &amp;&amp; target.href != null) {
          alert("hello"); // works when middle click on a link
          // but these preventing doesn't works here:
          e.preventDefault();
          e.stopPropagation();
          // link will still be opened in a new tab
      }
  });
  </code></pre>
  
  <p>But this method doesn't prevent link from opening in a new tab when middle click</p>
  
  <p>How can I make Microsoft Edge behave like Google Chrome or Firefox?</p>