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']?>"
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;
}