Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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=""> 
like image 297
Ilan Kleiman Avatar asked Nov 22 '15 21:11

Ilan Kleiman


People also ask

Why is my back button not working on Safari?

Most links that you click on tend to open in the same browser tab. But if the Back button on a page that you just loaded appears grayed out, that's likely because it opened up in a new tab or window. In that case, you can't use the Back button. The only way to go back to the previous page is to switch tabs or windows.

Why does Safari reload page when I go back?

Safari browser has its memory management system, which kills the inactive webpage whenever it needs more RAM. Next time when you revisit the old inactive tab, it automatically starts reloading the page. It is an excellent feature of RAM management.

How do I restore the back button in Safari?

How do I get it back? Answer: A: Answer: A: Choose Show Toolbar or Customize Toolbar from the View menu and put it back.

How do I stop a page from reloading the back button is pressed?

You have to detect browser back button event and pass as an input of the page you want do prevent URL reload that indicates you if you came from a back button click. this code: $(window). on('popstate', function(event) { alert("pop"); });


1 Answers

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);
like image 133
Dtipson Avatar answered Nov 05 '22 12:11

Dtipson