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?
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");
.
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.