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

170
Visualizações
JavaScript remove last History entries with same URL

I have a POST form (simple HTML, no JS involved in submission) which is partially validated server-side. When I submit it, server may return a redirect if there are any errors. Let’s say, the form is on /myform URI, but if the server found errors in data it will redirect to /myform?error. After this is done several times and finally correctly submitted, user may want to use his browser’s back button. But it makes user to go through all the steps of failed submission attempts, e.g. /myform?success -> /myform?error -> /myform -> /home.

How do I prevent this? My guess is to remove last History entries that have same URI. How do I achieve that? Or is there another better way? I use server side rendering with Spring (Java) so dynamic validation is not really an option for the use-case. Thank you in advance!

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

0

For security and privacy reasons, you can't view or modify a user's browser history.

However, if you're willing to use JavaScript, you can use the History API to replace the current page's state on successful submit:

history.replaceState(null, 'Page title', '/form-url');

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

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