title: Capture the event click of "Open Link in New Tab" javascript or jquery - Cloaking URL
body: <p>I know that I can capture the events of click: left, right and middle button by:</p>
  
  <pre><code>contextmenu    
  e.which
  </code></pre>
  
  <p>But, I need to capture the event click of "Open Link in New Tab":
  When you do right click in a link, it shows a menu with the option "Open Link in New Tab".</p>
  
  <p>How can I capture that event ?</p>
  
  <p>PD: is not the right click event, is the event when you do click in "Open Link in New Tab".</p>
  
  <p>The main reason is, I'm trying to cloak links for affiliated sites, but when I do right click and choose the option "Open Link in New Tab", not working, it doesn't show me the real hidden url.</p>
  
  <p>I found the script searching in google but I edited the script to my needs, but I have the problem that I told above.</p>
  
  <p>The code:</p>
  
  <pre><code>(function ($) {
  
      ninja_href(".ninja-href");
  
  function ninja_href_call(e,which)
  {
  
    var ninja_url = e.target.getAttribute('data-ninja-url');
    var ninja_target = e.target.getAttribute('data-ninja-target');
  
    if(ninja_target == null || typeof ninja_target == undefined || which === 3)
    {
      ninja_target = "_self";
    }
  
    if(which === 2)
    {
      ninja_target = "_blank";
    }
  
  
    var win = window.open(ninja_url, ninja_target);
    if (win &amp;&amp; ninja_target == "_blank")
    {
      win.focus();
    }
  }
  
  
  
  function ninja_href(element)
  {
    if(element == null || typeof element == undefined){
      element = ".ninja-href";
    }
  
    if (document.addEventListener) 
    {
      document.addEventListener('click', function(e) {
        if(e.target &amp;&amp; e.target.matches(element))
        {
          if (e.which === 1 || e.which === 2) 
          {
            e.preventDefault();
            ninja_href_call(e,e.which);
  
          }
        }
      }, false);
  
      document.addEventListener('mousedown', function(e) {
          if(e.target &amp;&amp; e.target.matches(element))
          {
              if (e.which === 2) 
              {
                  e.preventDefault();
                  ninja_href_call(e,e.which);
  
              }
          }
  
      }, false);
  
      document.addEventListener('contextmenu', function(e) {
          console.warn(e);
        if(e.target &amp;&amp; e.target.matches(element))
        {
  
        }
      }, false);
    } else {
      document.attachEvent('click', function() {
        if(e.target &amp;&amp; e.target.matches(element))
        {
          if (e.which === 1 || e.which === 2) 
          {
            e.preventDefault();
            ninja_href_call(e,e.which);
  
          }
        }
      });
  
    }
  
  }
  
  }(window.jQuery));
  </code></pre>
  
  <p>Any idea</p>