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

276
Visualizações
window.location.href works offline but anchor tag does not

I am building a progressive web app (PWA) that is usable offline.

On the page, I use the link to navigate back to the previous page like this.

<a href="/alink">Back<a>

It doesn't work but causes the No Internet.

On the other hand, the window.location.href does navigate to the previous page even when I'm offline.

Why does this happen? What is the difference between a tag and window.location.href?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

The a tag will redirect to the new page by going forward to it.
However the window.location.href will just change the route in the URL. But not actually redirect the page.

If you want to go back, try using the window history. As this is what things like react router use to move around different paths.

https://developer.mozilla.org/en-US/docs/Web/API/Window/history

Hope this helps.

about 4 years ago · Juan Pablo Isaza Relatório

0

The a tag always redirects you to a new page which is required a network connection. If you want to get back to the previous page with the a tag. You can use this

<a href="javascript:history.back()">Back</a>

It will navigate you back to the cached page that you loaded before going offline.

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