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

280
Visualizações
Use the browser/system default behaviour on window.open(url)?

I am working on making some cards more accessible. To do so, I need to use JavaScript to take the one link from the Card Title and apply it to all elements inside the card.

It is working relatively well.

The problem, though, is that it is opening the link in a new TAB every time I click. Not just when I hold down CMD (Mac).

I know some users (like me) love this. But it is over riding the default behaviour and I'd like to some how find a way to get window.open(url) to just follow the default behaviours that the user is used to using.

I've tried:

window.open(url, "_blank")
window.open(url, "_self")
window.open(url, "_top")

JavaScript below:

        function cardLinks() {
            let cards = document.querySelectorAll(".card");

            cards.forEach(function (box) {
                let link = box.querySelector("a");
                if (link) {
                    let url = link.getAttribute("href");
                    box.addEventListener("click", function () {
                        window.open(url)

                    });
                }
            });
        }
        document.addEventListener("DOMContentLoaded", function () {
            if ("querySelector" in document) {
                cardLinks();
            }
        });

If you have read this far, the reason this is important (to me at least) is that having seperate link tags on the HTML card element is a nightmare for accessibility users. As they need to tab through multiple links. Having an event handler on all the children of the card means that it works well for accessibility users and visual users.

Hope someone can help.

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