【问题标题】:Alternative Javascript Method for PerformanceNavigation (Cross-browser Compatible)PerformanceNavigation 的替代 Javascript 方法(跨浏览器兼容)
【发布时间】:2020-12-26 09:37:15
【问题描述】:

我已经成功实现了以下 Javascript,但在实现与 window.performance.navigation 的跨浏览器兼容性(特别是在 Firefox 中)时遇到了一些困难,因为它已被弃用。

到目前为止,这是我已经实现的:

window.addEventListener("load",function(event){
    var historyTraversal=event.persisted||
    (typeof window.performance!=="undefined"&&
    window.performance.navigation.type===2);
    if(historyTraversal){
        window.history.back();
    }
});

还有其他的格式化方法吗?

【问题讨论】:

    标签: javascript performance firefox cross-browser compatibility


    【解决方案1】:

    正如MDN 中所述,Performance.navigation 已被弃用,因为它在Navigation Timing Level 2 specification 中被标记为这样。按照规范的建议,应该改用PerformanceNavigationTiming:这与所有最新的主流浏览器兼容。

    您要找的房源现在here,您可以查询var perfEntries = performance.getEntriesByType("back_forward");

    【讨论】:

      【解决方案2】:

      不幸的是,它在 Safari 中不起作用。

      确实如此(参见Safari back button doesn't reload page when used):

      window.addEventListener("pageshow", function(evt){
          if(evt.persisted){
          setTimeout(function(){
              window.location.reload();
          },10);
      }
      }, false);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-08-09
        • 2015-03-07
        • 2016-09-30
        • 1970-01-01
        • 2011-06-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多