window.history.go(-1);//返回上一頁不刷新 window.history.back(); //返回上一頁 window.location.href = document.referrer;//返回上一頁並刷新,真正實現頁面后退並刷新頁面 history.go(1);//前進一頁 history.forward(); //前進一頁 history.length;//用length屬性查看歷史中的頁面數
因為windows對象引用不是必須的。所以windows.history.go() == history.go()的。
<button οnclick="history.go(-1);">返回上一頁</button> <a href="javascript:history.back();">返回上一頁</a>
history.go(-1)和history.back()的區別
1.history.go(-1)表示后退與刷新。如數據有改變也隨之改變
2.history.back()只是單純的返回到上一頁。
Javascript刷新頁面的幾種方法:
history.go(0); location.reload(); location=location; location.assign(location); document.execCommand('Refresh'); window.navigate(location); location.replace(location); document.URL=location.href ;
