Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!