最近遇到一個需求:培訓學習的資料頁面,用戶點了某資料后,會跳轉到學習頁面,當返回到資料頁時,該資料置為“已學習”狀態。遇到的問題是,用了瀏覽器的返回時,資料頁不會刷新。方法應該有很多,不過從網上找到了一種,比較方便,寫在這里方便自己以后查找
將下面js放在學習頁面,當返回資料頁面時,就可以看到頁面更新啦
$(function(){
if (window.history && window.history.pushState) {
$(window).on('popstate', function () {
window.history.pushState('forward', null, '#');
window.history.forward(1);
location.replace(document.referrer);//刷新
});
}
window.history.pushState('forward', null, '#'); //在IE中必須得有這兩行
window.history.forward(1);
});
工作至今,感謝優秀的大神們