<script type=
"text/javascript"
>
//重新加载后滚动条回到原来的位置
function window.onload() {
var
arr;
//cookie中保存的有值,则将滚动条返回到原来的位置
if
(arr = document.cookie.match(/scrollTop=([^;]+)(;|$)/))
{
document.documentElement.scrollTop = parseInt(arr[1]);
document.body.scrollTop = parseInt(arr[1]);
}
}
//页面刷新前保存滚动条位置信息到cookie
function window.onbeforeunload() {
var
scrollPos;
if
(
typeof
window.pageYOffset !=
'undefined'
) {
scrollPos = window.pageYOffset;
}
else
if
(
typeof
document.compatMode !=
'undefined'
&& document.compatMode !=
'BackCompat'
) {
scrollPos = document.documentElement.scrollTop;
}
else
if
(
typeof
document.body !=
'undefined'
) {
scrollPos = document.body.scrollTop;
}
document.cookie =
"scrollTop="
+ scrollPos;
}
</script>
来源:CSDN
作者:疯子艾
链接:https://blog.csdn.net/qq_34469454/article/details/79968500