Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

263
Vistas
JavaScript: How do I fire an event when a user has accessed the page via back/forward buttons?

There is a number of threads here on StackOverflow concerning how to catch the back/forward button, but that's not what I want to do. I want to fire a method each time a page is loaded by pressing the back/forward button. So not on the page, where the user clicked back/forward, but on the page that the user got to after clicking back/forward.

I also tried looking at events using Chrome and I haven't found any event that is firing when coming back or going forward to a page.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use https://developer.mozilla.org/en-US/docs/Web/API/Window/popstate_event

The popstate event will be triggered by doing a browser action such as a click on the back or forward button (or calling history.back() or history.forward() in JavaScript).

First you can save the info that user has navigated to localStorage or cookie, and then you can check if that localStorage entry or cookie exists on the next page load event.

If it exists, user has navigated to that page using back/forward buttons, you can do whatever you need to do, and clear the localStorage entry/cookie.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda