Home>

Always I am indebted.

Please tell me about the behavior when you press the back button of the browser.
For example, if you click a specific row to call a script that deletes records from the database list screen and move to the screen that displays the results, then click the browser's back button to return to the original list screen. Since the cache is enabled, it will be in the state it was in before the record was deleted.

Of course, if you press F5 on the screen, it will be erased, but is it possible to get the event when the back button is pressed and displayed and reload it?

In the article on the net, I saw some things that I could do, so I implemented the following script on the screen on the side I want to reload, but none of them work.

<script type = "text/javascript" src = "http: //*/sample.js? date = (new Date ()). getTime ()"></script>
<script type = "text/javascript">
// pattern1
window.onpageshow = function (event) {
    if (event.persisted) {
        alert ("reload");
        window.location.reload ();
    }
};
// pattern2
window.addEventListener ('popstate', function (e) {
    alert ("reload");
    window.location.reload ();
});
// pattern3
window.onbeforeunload = function () {
    alert ("reload");
    location.reload (true);
};
</script>


Both Chrome and FireFOX were NG.
Is it the correct way to prohibit the back button and add a button to transition to the original list screen?

  • Answer # 1

    I don't recommend it because it's a process that seems to fit
    If you want to reload when you come back in history

    window.addEventListener ('pageshow', () =>{
      if (window.performance.navigation.type == 2) location.reload ();
    });

Related articles