项目中,经常遇到用户一直退步出去的问题,这种问题有两种解决办法:
1、控制用户的前进方向,比如
history.go(-1) , history.go(-2)等等。
2、用window.location.pushState()和window.onpopstate()组合方法,
<script>
console.log('1111 '+ history.length);
var json={time:new Date().getTime()};
// @状态对象:记录历史记录点的额外对象,可以为空
// @页面标题:目前所有浏览器都不支持
// @可选的url:浏览器不会检查url是否存在,只改变url,url必须同域,不能跨域
window.history.pushState(json,"","#abcd");
console.log('2222 '+ history.length);
// 当前的url为:http://qianduanblog.com/post-1.html
window.onpopstate=function()
{
// 获得存储在该历史记录点的json对象
var json=window.history.state;
// 获得json为{time:1369647895656}
console.log('3333'+ json);
console.log('4444'+ history.length);
location.replace('/bybbm/note/showPagePatientDetailNew.action?id=3978');
//alert('aaaa');
}
</script>