简体   繁体   中英

Safari back button doesn't reload page when used

This issue -was- solved in older versions of Safari ( The Safari Back Button Problem ). Although running the latest Safari (9.0.1), none of the solutions listed on the previous answer work anymore. Does anyone have a solution to "refresh/reload" the page when the back button on safari is used?

This -was- a way to detect if the page was accessed using the back-button. Although doesn't work in the version of Safari I'm using.

<body onunload=""> 

Other answers bind things to window.onpageshow, but this is the only version that works for me: once your page is in a final state that you don't want to outlive a redirect, you can just bind the pageshow event and then check for the "persisted" property being true to determine if you should reload it.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM