html 保持历史页面状态,对于html页面历史记录的控制

项目中,经常遇到用户一直退步出去的问题,这种问题有两种解决办法:

1、控制用户的前进方向,比如

history.go(-1) , history.go(-2)等等。

2、用window.location.pushState()和window.onpopstate()组合方法,

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');

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值