0

I have semi-successfully implemented the following Javascript, but am having some difficulties achieving cross-browser compatibility (specifically in Firefox) with window.performance.navigation, since it has since been deprecated.

Here's what I've implemented, so far:

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

Any alternative ways to formatting this?

nr159
  • 191
  • 1
  • 14

2 Answers2

0

As mentioned on MDN, Performance.navigation is deprecated because it's marked as such in the Navigation Timing Level 2 specification. As recommended on the specs, PerformanceNavigationTiming should be used instead: this is compatible with all the latest major browsers.

The property you're looking for is now available here, and you can query it as var perfEntries = performance.getEntriesByType("back_forward");.

Dexter
  • 2,482
  • 27
  • 40
0

Unfortunately it doesn't work in Safari.

This does (see Safari back button doesn't reload page when used):

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