pageshow event on Safari

后端 未结 2 1682
滥情空心
滥情空心 2021-01-07 03:25

I have the following simple JavaScript, which I require in order to re-initialise some variables on page reload, specifically when the page is served from the Safari BFCache

相关标签:
2条回答
  • 2021-01-07 04:12

    I appeared to have solved the issue by instead binding to the popstate event:

    jQuery(window).bind('popstate', function(event) {
        // Do some initialisation here
    });
    

    which fires whenever the active history entry changes. This appears to fire consistently rather than just once, so achieves the goal of performing re-initialisation whenever a user lands on page, regardless of the mechanism for getting there.

    0 讨论(0)
  • 2021-01-07 04:31

    To disable the BFCache, you could add an onunload="" attribute on your html body.

    <body onunload=""></body>
    
    0 讨论(0)
提交回复
热议问题