Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

156
Vistas
Javascript causing some links not to work

I'm having an issue with this piece of JavaScript. The issue is that when it is enabled, some of my links aren't working. The links that open a webpage work fine, it's the mailto: and tel: links that won't work. Can someone please help me fix this issue? Thank you.

const allLinks = document.querySelectorAll("a:link");

allLinks.forEach(function (link) {
  link.addEventListener("click", function (e) {
    
    // conditional for preventDefault
    if (link.hasAttribute("target") === false) {
        e.preventDefault();
    } else {
      if (link.getAttribute("target") !== "_blank") {
        e.preventDefault();
      }
    }

    const href = link.getAttribute("href");

    // Scroll back to top
    if (href === "#")
      window.scrollTo({
        top: 0,
        behavior: "smooth",
      });
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your code is preventing the link from being followed if it doesn't have a target attribute set to "_blank".

Tel and mailto links don't usually have a target. As @The Fool mentioned, this looks suspicious and it's unclear how you expected it to work.

You can probably fix it by adding the following to the top of your handler.

if (link.href.startsWith("tel:")  || link.href.startsWith("mailto:")) {
    return
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda