监听浏览器返回事件
作者:
管子先生 | 来源:发表于
2018-02-01 11:10 被阅读0次function pushHistory() {
var state = {
title: "title",
url: "#"
};
window.history.pushState(state, "title", "#");
}
pushHistory();
var bool = false;
setTimeout(function () {
bool = true;
}, 1500);
window.addEventListener("popstate", function (e) {
if (bool) {
if (sessionStorage.getItem('addCar')) {
sessionStorage.removeItem('addCar');
window.location.replace('/');
}else{
window.history.back();
}
}
pushHistory();
}, false);
本文标题:监听浏览器返回事件
本文链接:https://www.haomeiwen.com/subject/svfdzxtx.html
网友评论