javascript - Keep scroll positions on page by url - Stack Overflow

Can you fix the script, which keeps position on difrent pages with no problem, until there you have som

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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744305489a4567710.html

相关推荐

  • javascript - Keep scroll positions on page by url - Stack Overflow

    Can you fix the script, which keeps position on difrent pages with no problem, until there you have som

    7天前
    60

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信