我有这个代码是为了知道页面是否被用户重新加载,不幸的是被弃用了。我想知道角度是否有这种方法。
if (performance.navigation.type === 1) {
console.log('is refreshed')
}
if (performance.navigation.type === 0) {
console.log('the user is arrived')
}
我有这个代码是为了知道页面是否被用户重新加载,不幸的是被弃用了。我想知道角度是否有这种方法。
if (performance.navigation.type === 1) {
console.log('is refreshed')
}
if (performance.navigation.type === 0) {
console.log('the user is arrived')
}
不是 Angular 特有的,但是这个 API 已经被PerformanceNavigationTiming替代了,它也有一个type
属性,但是它返回一个字符串而不是一个数字代码。
但是我只是注意到 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>
performance.navigation
已弃用。要获取导航类型,您可以使用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
我想添加运行:
performance.getEntriesByType("navigation");
在 Safari 中返回一个空数组