Foros del Web » Programando para Internet » Jquery »

Capturar evento click "Open Link in New Tab"

Estas en el tema de Capturar evento click "Open Link in New Tab" en el foro de Jquery en Foros del Web. Hola Estoy tratando de ocultar links ( cloaking links ) the sitios afiliados. El problema que tengo es que puedo capturar los click: izquierdo, derecho ...
  #1 (permalink)  
Antiguo 06/06/2018, 01:53
Avatar de kakashi20  
Fecha de Ingreso: septiembre-2009
Mensajes: 616
Antigüedad: 14 años, 7 meses
Puntos: 15
Exclamación Capturar evento click "Open Link in New Tab"

Hola

Estoy tratando de ocultar links ( cloaking links ) the sitios afiliados.

El problema que tengo es que puedo capturar los click: izquierdo, derecho y medio, pero cuando hago click derecho y me aparece el menu y escojo "open in new tab" no puedo capturar ese evento pars poder mostrar la url con los parametros UTM

Codigo:

Código Javascript:
Ver original
  1. (function ($) {
  2.  
  3.     ninja_href(".ninja-href");
  4.  
  5. function ninja_href_call(e,which)
  6. {
  7.  
  8.   var ninja_url = e.target.getAttribute('data-ninja-url');
  9.   var ninja_target = e.target.getAttribute('data-ninja-target');
  10.  
  11.   if(ninja_target == null || typeof ninja_target == undefined || which === 3)
  12.   {
  13.     ninja_target = "_self";
  14.   }
  15.  
  16.   if(which === 2)
  17.   {
  18.     ninja_target = "_blank";
  19.   }
  20.  
  21.  
  22.   var win = window.open(ninja_url, ninja_target);
  23.   if (win && ninja_target == "_blank")
  24.   {
  25.     win.focus();
  26.   }
  27. }
  28.  
  29.  
  30.  
  31. function ninja_href(element)
  32. {
  33.   if(element == null || typeof element == undefined){
  34.     element = ".ninja-href";
  35.   }
  36.  
  37.   if (document.addEventListener)
  38.   {
  39.     document.addEventListener('click', function(e) {
  40.       if(e.target && e.target.matches(element))
  41.       {
  42.         if (e.which === 1 || e.which === 2)
  43.         {
  44.           e.preventDefault();
  45.           ninja_href_call(e,e.which);
  46.  
  47.         }
  48.       }
  49.     }, false);
  50.  
  51.     document.addEventListener('mousedown', function(e) {
  52.         if(e.target && e.target.matches(element))
  53.         {
  54.             if (e.which === 2)
  55.             {
  56.                 e.preventDefault();
  57.                 ninja_href_call(e,e.which);
  58.  
  59.             }
  60.         }
  61.  
  62.     }, false);
  63.  
  64.     document.addEventListener('contextmenu', function(e) {
  65.         console.warn(e);
  66.       if(e.target && e.target.matches(element))
  67.       {
  68.  
  69.       }
  70.     }, false);
  71.   } else {
  72.     document.attachEvent('click', function() {
  73.       if(e.target && e.target.matches(element))
  74.       {
  75.         if (e.which === 1 || e.which === 2)
  76.         {
  77.           e.preventDefault();
  78.           ninja_href_call(e,e.which);
  79.  
  80.         }
  81.       }
  82.     });
  83.  
  84.   }
  85.  
  86. }
  87.  
  88. }(window.jQuery));

Alguna idea

Graciss

Etiquetas: evento, link, open
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 11:54.