document.referrer与页面访问来源演示页面
展示
代码
-
首页HTML:
<a href="./1-2.html">« 返回列表页</a>
详情页HTML:
<a href="./1-2.html">« 返回列表页</a>
-
本页HTML:
<div id="list" class="list"> <ul> <li><a href="./detail.html">详情页</a></li> <li class="text">撑开高度,形成滚动</li> <li><a href="./detail.html">详情页</a></li> </ul> </div>
-
JS代码:
list.addEventListener('scroll', function() { localStorage.listScroll = this.scrollTop; }); if (/detail\.html/.test(document.referrer)) { list.scrollTop = localStorage.listScroll; } else { localStorage.listScroll = 0; }