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

186
Vistas
In Javascript, is there a way to know the path is changed?

I am wondering, if there is a way to know(using events) that the path is changed? I looked into both onpopstate & onhashchange. Both are not what I am looking for. My current requirements are, in a single page application:

  1. When the url is changed from one to something else, I want a function to be called.
  2. When the page is loaded initially, the function for the current page to be called.

Are these possible with native API's in the browser?

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

0

Listen for the load event, which fires when the page has finished loading:

function code(){
    console.log('page loaded')
}

window.addEventListener('load', code)

To listen for pushState changes, you can override the default pushState behavior:

function trigger() {
  console.log('state change')
}

var pushState = history.pushState;
history.pushState = function(state) {
  if (typeof history.onpushstate == "function") {
    history.onpushstate({state: state});
  }
  trigger()
  return pushState.apply(history, arguments);
};

history.pushState(null, null, '/endpoint')

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