javascript window.performance.navigation.type 适用于 IE 和 Firefox,但不适用于 CHROME

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46226144/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 06:32:28  来源:igfitidea点击:

window.performance.navigation.type works in IE and Firefox but NOT in CHROME

javascriptjqueryreload

提问by Gsm

I have been trying to implement a functionality when the page refreshes. I figured that value of

我一直在尝试在页面刷新时实现一个功能。我想那个值

    window.performance.navigation.type 

turns 1 if the page reloads else, it is 0. I created an alert message on page load and the values are correct for IE and Firefox but it remains "0" for Chrome throughout no matter how many times the page reloads. I have also tried windows.onbeforeunload as per other stackoverflow answers but nothing seems to work!

如果页面重新加载,则变为 1,则为 0。我在页面加载时创建了一条警报消息,这些值对于 IE 和 Firefox 是正确的,但无论页面重新加载多少次,Chrome 始终保持“0”。我也尝试过 windows.onbeforeunload 根据其他 stackoverflow 答案,但似乎没有任何效果!

How do I resolve this?

我该如何解决?

OR

或者

Is there another way to detect a page reload that works on all the browsers?

是否有另一种方法来检测适用于所有浏览器的页面重新加载?

Thanks!

谢谢!

回答by conorgil

As of 2017-11-01, Chrome (61.0.3163.100) does support the performance.navigation API. See this gistfor some sample code that you can throw into a page and see it working.

截至 2017 年 11 月 1 日,Chrome (61.0.3163.100) 确实支持 performance.navigation API。请参阅此要点以获取一些示例代码,您可以将其放入页面并查看其工作情况。

I cannot find the Chromium ticket tracking the development, but this Chromium blog postlinks to the W3 spec that defines the performance.navigation API, so perhaps it was supported fully in a recent release.

我找不到跟踪开发的 Chromium 票证,但是这篇 Chromium 博客文章链接到定义 performance.navigation API 的 W3 规范,所以也许它在最近的版本中得到了完全支持。

回答by Dekel

According to the docs, the Performance.navigationproperty returns a PerformanceNavigationobject.

根据文档,该Performance.navigation属性返回一个PerformanceNavigation对象。

Checking the browsers compatibilityat the bottom of the page you can see that chrome is not supported.

检查页面底部的浏览器兼容性,您可以看到不支持 chrome。