Is there a cross-browser onload event when clicking the back button?

后端 未结 15 2286
被撕碎了的回忆
被撕碎了的回忆 2020-11-21 22:46

For all major browsers (except IE), the JavaScript onload event doesn’t fire when the page loads as a result of a back button operation — it only fires when the

15条回答
  •  旧巷少年郎
    2020-11-21 23:12

    OK, here is a final solution based on ckramer's initial solution and palehorse's example that works in all of the browsers, including Opera. If you set history.navigationMode to 'compatible' then jQuery's ready function will fire on Back button operations in Opera as well as the other major browsers.

    This page has more information.

    Example:

    history.navigationMode = 'compatible';
    $(document).ready(function(){
      alert('test');
    });
    

    I tested this in Opera 9.5, IE7, FF3 and Safari and it works in all of them.

提交回复
热议问题