Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

287
Visualizações
Make the <a> tag open two URLs (in two different pages)

I wanted to make the tag open two URLs at the same time. This is what I tried:

Only HTML

<a href="URL1" target="_blank" onclick="window.open('URL2');">text</a>

This did work but not the way I wanted it to. It would open the URL2 when clicked on it and if opened in a new tab with right click or the mouse wheel it would open URL1. I want it to open both pages in new tabs at the same time.

HTML + JavaScript HTML:

<a id="myId">text</a>

JS:

myId.onclick = function(){
open('https://www.example1.com');
location.href = ('https://www.example2.com');
}

This didn't work at all.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

This is Your code :

     myId.onclick = function(){
        open('https://www.example1.com');
        location.href = ('https://www.example2.com',,'_blank');
        }

Change the code to:

    myId.onclick = function(){ 
    window.open('https://www.example1.com','_blank');  //just use window.open() for both the cases;
    window.open('https://www.example2.com','_blank');
    }

Hope, you have got the solution for your problem.

over 4 years ago · Santiago Trujillo Relatório

0

Try using an onclick function that uses the window.open method to open the two URLS:

    document.querySelector("#foo").onclick = function () {
      window.open('https://www.example.com', "_blank");
      window.open('https://www.example.com', "_blank");
    }


    <a id="foo">bar</a>

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda