JS(history,location的使用)返回上一頁以及返回上一頁並刷新


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 ;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM