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

201
Vistas
Create and click A element with target blank

I need to create a new <a> element with the download property and target blank. This link must not be visible in html and will be clicked with JavaScript.

let a = document.createElement("a");
document.body.appendChild(a);
a.setAttribute("style", "display: none");
a.href = blobUrl;
a.target = "_blank";
a.download = "MyFileName.pdf";
a.click();

Result in HTML: enter image description here

The problem is that the target blank seems to be ignored. It worked until recently and there have been no changes. What could be the problem?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try this, and also please move the document.body.appendChild(a); to the end just like what I have done.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>


<script>

    function createA(){
        let a = document.createElement("a");
        a.setAttribute("style", "display: none");
        a.href = "#";
        a.target = "_blank";
        a.download = "MyFileName.pdf";
        a.click();
        a.innerHTML = "SomeText";
        document.body.appendChild(a);
    }
    
    createA();
</script>

</body>
</html>

The final result for me Please let me know if your problem has been solved by voting the answer :)

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