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

129
Visualizações
Is there a way to make a click event have the same behavior as after clicking a link?

When we click a link like <a href="https://stackoverflow.com/">A link</a>, the current page will be redirected to the given URL. But we'll be led to a new tab if we cmd/ctrl+click it. I wonder that is there a browser interface(something like window.open()) in JS that can give the click event of a non-a tag the same behavior above? The solution I got from the Internet is all about detecting e.metaKey/ctrlKey to decide whether to add _blank to the window.open() or not. The solution is tricky and still has some differences from the expected behavior. Maybe we can just simply use the <a> tag directly to avoid this. But can this be the solution for all situations? And could you guys please give me the reason if there's indeed not a pure JS way to simulate the event? Cuz it's weird to me.

about 4 years ago · Juan Pablo Isaza
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