Browser “Back” Button vs. jQuery-animated page

后端 未结 3 934
攒了一身酷
攒了一身酷 2020-12-15 23:42

I have a challenging problem I\'ve been battling for some time now.

The Problem: when I go back to previous page using browser\'s back button, the page is d

3条回答
  •  抹茶落季
    2020-12-16 00:29

    The above answers touch on the problem, but provide hacky ways to solve the question. This seems to be the proper way to do it.

    $(window).bind('pageshow',function(){
        alert("This page will run even if the back button was pressed!");
    });
    

    To read more on the pageshow/pagehide events see here: http://www.webkit.org/blog/516/webkit-page-cache-ii-the-unload-event/

    You could can take it a step further like this:

    $(window).bind('pageshow',function(e){
            if (e.persisted) {
                alert("pageshow event handler called.  The page was just restored from the Page Cache.");
            } else {
                alert("pageshow event handler called for the initial load.  This is the same as the load event.");
            }
    }
    

提交回复
热议问题