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

150
Views
Prevent jumping to hash on initial load of URL consisting a hash

It is possible to prevent jumping to hash when hash changes with the following function for example:

function handleHashChange() {
   const scrollY = window.pageYOffset;
   window.scrollTo({top: scrollY});
}

But this only works if the hash is changed later. When a page with a URL that already consists a hash is loaded, this does not work. (For example: mysite.com/posts/#popular) I guess maybe because native hashchange event is sent to Callback Queue before custom hashchange event listener is added.

Is there any workaround to this problem ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

So, it appears that, all that needs to be done is calling that scroll function inside load event listener:

window.addEventListener('load',()=>{
    const scrollY = window.pageYOffset;
      setTimeout(() => {
        window.scrollTo({top: scrollY});
      }, 0);
  });
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!