更新:如@Paolo 所述,performance.navigation已弃用,请改用PerformanceNavigationTiming。
该导航计时API,具体PerformanceNavigation.type,会告诉你的页面访问模式。
0 - TYPE_NAVIGATE
该页面是通过点击链接、书签、表单提交、脚本或在地址栏中键入 URL 来访问的。
1 - TYPE_RELOAD
该页面是通过单击重新加载按钮或通过 Location.reload() 方法访问的。
2 - TYPE_BACK_FORWARD
该页面是通过导航到历史记录访问的。
第255话
任何其他方式。
示例用法:
// does the browser support the Navigation Timing API?
if (window.performance) {
console.info("window.performance is supported");
}
// do something based on the navigation type...
switch(performance.navigation.type) {
case 0:
console.info("TYPE_NAVIGATE");
break;
case 1:
console.info("TYPE_RELOAD");
break;
case 2:
console.info("TYPE_BACK_FORWARD");
break;
case 255:
console.info("255");
break;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3145 次 |
| 最近记录: |