pageshow event on Safari

后端 未结 2 1707
滥情空心
滥情空心 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.

提交回复
热议问题