admin管理员组文章数量:1405393
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>
本文标签: javascriptKeep scroll positions on page by urlStack Overflow
版权声明:本文标题:javascript - Keep scroll positions on page by url - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744305489a2599791.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论