本文介绍了从PerformanceNavigationTiming确定导航类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经使用 window.performance.navigation.type

if (window.performance.navigation.type === 2) {
    window.location.reload()
}

我看到此属性已被。我该如何模仿Performance.navigation api的行为?

I saw that this property has been deprecated and succeeded by Navigation Timing Level 2. How can I mimic the behavior of performance.navigation api by this?

推荐答案

我应该以说我不是JavaScript开头亲这是我利用的方法。 p>

I should preface this by saying that I am not JavaScript pro. This is my approach for utilizing Navigation Timing Level 2.

if (String(window.performance.getEntriesByType("navigation")[0].type) === "back_forward") {
    window.location.reload()
}

window.performance.getEntriesByType( navigation)返回每个集。如果您未设置任何标记,则此列表将包含一个具有窗口导航信息的对象。

window.performance.getEntriesByType("navigation") returns a list of PerformanceEntry objects every mark set. If you haven't set any marks, this list contains a single object that has the navigation information for the window.

这篇关于从PerformanceNavigationTiming确定导航类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 18:17