我有一个HTML网页,我想记住包含大量信息的滚动位置,当我想打开div时,页面刷新,我怎样才能让页面记住当前的滚动位置?
答案 0 :(得分:0)
function load_save_scroll() {
// get scrolltop value
var doc = document.documentElement;
var top = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
// make http get request
var xhr = new XMLHttpRequest();
xhr.open('GET', '/my_reload_div', true);
xhr.send();
xhr.onreadystatechange = function() { // (3)
if (xhr.readyState != 4) return;
// push xhr.responseText to 'my_div' element
// restore scrolltop
window.scrollTo(0,top);
}
}