3 回答

TA貢獻(xiàn)1836條經(jīng)驗 獲得超4個贊
不是 Angular 特有的,但是這個 API 已經(jīng)被PerformanceNavigationTiming取代,它也有一個type屬性,但它返回一個字符串而不是數(shù)字代碼。
但是我只是注意到 Chrome 不會為 iframe 公開它,它總是會輸出"navigate".
以下代碼段在 Chrome 中不起作用,請在外部視圖中嘗試使用此 plnkr。
const entries = performance.getEntriesByType("navigation");
console.log( entries.map( nav => nav.type ) );
rel.onclick = e => location.reload();
<button type="button" id="rel">reload</button>
<a href="404">go to 404 (come back with your browser's back button)</a>

TA貢獻(xiàn)1786條經(jīng)驗 獲得超13個贊
performance.navigation已棄用。要獲取導(dǎo)航類型,您可以使用getEntriesByType
例子
console.log(performance.getEntriesByType("navigation")[0].type)
該type值可以是
enum NavigationType {
"navigate",
"reload",
"back_forward",
"prerender"
};
查看更多:https : //w3c.github.io/navigation-timing/#sec-performance-navigation-types

TA貢獻(xiàn)1868條經(jīng)驗 獲得超4個贊
我想添加運行:
performance.getEntriesByType("navigation");
在 Safari 中返回一個空數(shù)組
添加回答
舉報