【发布时间】:2014-11-08 17:46:12
【问题描述】:
因此,我有代码来存储带有抽屉菜单的响应页面的滚动位置和高度。
$(window).on('beforeunload', function (e) {
if (window.history && window.history.replaceState) {
var $formContainer = $('#Form1'),
$drawerContent = $('#drawer-content'),
pageState = {
page: window.location.href,
formContainerHeight: $formContainer.height(),
drawerContentScrollTop: $drawerContent.scrollTop()
};
console.log(pageState, e.type)
window.history.replaceState(pageState, window.document.title);
}
});
在页面加载时,我控制台记录 window.history.state 以确保在历史记录中返回/前进时的页面大小。
我在 IE10+、FireFox 和 Opera 中获得了预期值,但 chrome 似乎在历史 +1 中记录了页面中的值。
【问题讨论】:
标签: javascript html google-chrome onbeforeunload html5-history