Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
evitar el evento de clic en el enlace, excepto que se presione la tecla de acceso rápido para abrir en una nueva ventana

Entonces tengo mi sitio web, un sitio web sin recargar entre cambios de sitio. Por razones de SEO, mis enlaces se ven así:

 <a href="/site2" id="viewmore">View more</a> <script> // code is strongly simplified, for more clarity document.getElementById("viewmore").addEventListener("click",function(e) { e.preventDefault(); myHandler.goTo(e.currentTarget.href); }); </script>

myHandler es el controlador del sitio en este caso.

Si hago clic en la tecla de acceso directo para abrir un enlace en una nueva pestaña (en Mac es CMD+Click), no funciona, ya que se evita el evento.

¿Cómo verificar si el enlace debe abrirse en una nueva pestaña o no? (Compruebe si la tecla de acceso rápido está presionada o no)

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

No estoy seguro de haberlo entendido, pero prueba esto

 document.getElementById("viewmore").addEventListener("click", (e) => { // ctrlKey / altKey / shiftKey if (e.ctrlKey) myHandler.goTo(e.currentTarget.href); else e.preventDefault(); });
about 4 years ago · Juan Pablo Isaza Report

0

Puede almacenar el estado de la clave CMD en una variable y verificarlo cuando se hace clic en el enlace.

 let isCmdPressed = false; document.addEventListener("keydown",(e)=>{ if (e.key == "Meta"){ isCmdPressed = true; } }); document.addEventListener("keyup",(e)=>{ if (e.key == "Meta"){ isCmdPressed = false; } }); document.getElementById("viewmore").addEventListener("click",function(e) { if (!isCmdPressed){ e.preventDefault(); myHandler.goTo(e.currentTarget.href); } });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!