當前的頁面的url下標為0,所以window.history.go(-1) 就是要定位到相對頁面下表為-1的頁面, 也就是之前剛剛訪問的頁面;
//返回上一頁:
window.history.go(-1); //返回上兩個頁面:
window.history.go(-2);
window.history.back(-1)和windos.history.go(-1) 都是返回之前的頁面 但是方法不同 所以也有所區別:
window.history.back(-1)//直接返回當前頁的上一頁,數據全部消失,是個新頁面
window.history.go(-1)//也是返回上一頁面,不過表單的數據還在
項目經驗實例:
<button type="button" class="btn btn-danger" style="position:relative; float:right;bottom:49px;"
onclick="javascript:window.history.go(-1)">返回
總結:
<input type=button value=刷新 onclick="window.location.reload()">
<input type=button value=前進 onclick="window.history.go(1)">
<input type=button value=后退 onclick="window.history.go(-1)">
<input type=button value=前進 onclick="window.history.forward()">
<input type=button value=后退 onclick="window.history.back()"> //后退+刷新