87,997
社区成员




pushHistory();
window.addEventListener("popstate", function(e) {
if(document.referrer == ''){
window.location = "没有referrer将跳转的指定页面地址";
}else{
window.history.go(-1);
}
}, false);
function pushHistory(){
var state = {
title: "title",
url: "#"
};
window.history.pushState(state, "title", "#");
}
用cookie不好。应该用sessionStorage
<script type="text/javascript">
var historyArr = JSON.parse(sessionStorage.historyArr||"[]");
console.log(historyArr);
if (historyArr[0] != location.href) {
historyArr.unshift(location.href);
sessionStorage.historyArr = JSON.stringify(historyArr);
}
function historyBack() {
if (historyArr.length<2) return;
historyArr.shift();
sessionStorage.historyArr = JSON.stringify(historyArr);
location.href = historyArr[0];
}
</script>
<input type="button" value="返回上一页面" onclick="historyBack();" />