Can you fix the script, which keeps position on difrent pages with no problem, until there you have some pages with redirected to same php file, but different URL (thanks RewriteRule)? Would like to keep position even with atributes in URL. For example - page1.php is same as page1.php&abc=1 but diferent of page2.php. This script takes all these pages as same URL so it keeps same position, even if you did not visited second page yet.
.htaccess
RewriteRule page1\.php detail.php
RewriteRule page2\.php detail.php
RewriteRule page3\.php detail.php
script:
<script>
document.addEventListener("DOMContentLoaded", function (event) {
var scrollpos = localStorage.getItem("scrollpos");
if (scrollpos) window.scrollTo(0, scrollpos);
});
window.onscroll = function (e) {
localStorage.setItem("scrollpos", window.scrollY);
};
</script>