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

208
Visualizações
Prevent navigation if the target is the current page

In many web applications built with ASP.NET templates (new and old) there is a link at the top-left which is a link to the homepage of the site.

what I typically do is add some onclick logic to disable the click if we are already on the homepage to avoid unnecessary or errant page reloads.

Basically: Don't try to navigate to an address if I am already there.

<a href="/" onclick="return this.href!==location.href" class="navbar-brand" title="My New App">My App</a>

This code will prevent the click if the target href is the same as the href of the current location.

onclick="return this.href!==location.href"

Question: Can I do this at the document, window or location level instead of on each and every link?

I use this sparingly now, but it would be nice to paint with a broader brush.

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