javascript - 从 PerformanceNavigationTiming 确定导航类型
问题描述
我曾经通过单击上一页中的后退按钮来确定用户是否来过,使用window.performance.navigation.type
like
if (window.performance.navigation.type === 2) {
window.location.reload()
}
我看到此属性已被Navigation Timing Level 2弃用并成功。我怎样才能模仿 performance.navigation api 的行为?
解决方案
我应该先说我不是 JavaScript 专业人士。这是我利用Navigation Timing Level 2的方法。
if (String(window.performance.getEntriesByType("navigation")[0].type) === "back_forward") {
window.location.reload()
}
window.performance.getEntriesByType("navigation")
返回每个标记集的 PerformanceEntry 对象列表。如果您没有设置任何标记,则此列表包含一个具有窗口导航信息的对象。
推荐阅读
- python - 我有大量数据,我想实现以下操作但需要太多时间。我该如何优化它?
- nuget - Gitlab CI/CD yml 文件,用于构建、打包和部署 .net 标准类库作为 nuget 到 nexus 存储库
- python - 使用 Mock() 在 Python 中模拟嵌套对象
- arrays - Json 响应 - 访问数组中的对象
- mysql - 使用带有 sum 子句的左连接问题
- java - 如何在 switch 语句中重置我的值?
- c# - IndexOutOfRangeException - 音频频谱问题
- c# - 如何使用 C# 连接到 IBM COS API 并执行存储桶操作
- xamarin - Proguard 出错 - “java”以代码 1 退出
- logstash - 如何使用经过的过滤器-logstash