Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

65
Views
How to prevent jumping to top of the page when clicking on a link?

I have been stuck on how to prevent jumping to the top of the page when clicking on a link that has parsing PHP data.

I have tried so many things, like preventDefault or return false or putting "/" at the end, but unfortunately with no success. Observation: this is linking to the same page, but is sending a php value.

The link looks like this:

<a id="chatLink" href="explore.php?user_id=<?php echo $row['unique_id']?>"
7 months ago · Juan Pablo Isaza
1 answers
Answer question

0

First you need to store scrollValue before leaving page:

window.onscroll = e => localStorage.setItem('scrollTop', document.body.scrollTop);

Then, when new page load, set scroll back:

window.onload = e => {
    const scrollTop= localStorage.getItem('scrollTop');
    document.body.scrollTop = scrollTop;
}
7 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs