Fire JQuery/ Javascript after Back Button in Safari 9

允我心安 提交于 2019-12-25 09:48:49

问题


When I navigate back using the browser back button in Chrome/ Firefox my website works just as expected (the same as it would if loaded without navigating backward).

In Safari after navigating back I can't get any 'on load' type event to fire whether the standard document ready or some hackaround found on here on StackOverflow. I'm not doing anything special, I just really need to call:

$( document ).ready(function() {
  // analyticsEvent();
  // startAnimation();
  // etc();
});

Has anyone encountered the same problem?


回答1:


Try this

$(window).bind("pageshow", function(event) {
    if (event.originalEvent.persisted) {
        window.location.reload() 
    }
});


来源:https://stackoverflow.com/questions/36750707/fire-jquery-javascript-after-back-button-in-safari-9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!