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

181
Visualizações
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 Respostas
Responde à pergunta

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 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