js判斷是否瀏覽器返回

NO IMAGE
1 Star2 Stars3 Stars4 Stars5 Stars 給文章打分!
Loading...

https://developer.mozilla.org/en-US/docs/Web/API/PerformanceNavigation/type

if(performance!=undefined && performance.navigation.type==2){
           //do something
}

ValueConstant nameMeaning
0TYPE_NAVIGATEThe page was accessed by following a link, a bookmark, a form submission, a script, or typing the URL in the address bar.
1TYPE_RELOADThe page was accessed by clicking the Reload button or via the Location.reload() method.
2TYPE_BACK_FORWARDThe page was accessed by navigating into the history.
255TYPE_RESERVEDAny other way.

前端開發 最新文章