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

后端 未结 15 2316
被撕碎了的回忆
被撕碎了的回忆 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:30

    I have used an html template. In this template's custom.js file, there was a function like this:

        jQuery(document).ready(function($) {
    
           $(window).on('load', function() {
              //...
           });
    
        });
    

    But this function was not working when I go to back after go to other page.

    So, I tried this and it has worked:

        jQuery(document).ready(function($) {
           //...
        });
    
       //Window Load Start
       window.addEventListener('load', function() {
           jQuery(document).ready(function($) {
              //...
           });
       });
    

    Now, I have 2 "ready" function but it doesn't give any error and the page is working very well.

    Nevertheless, I have to declare that it has tested on Windows 10 - Opera v53 and Edge v42 but no other browsers. Keep in mind this...

    Note: jquery version was 3.3.1 and migrate version was 3.0.0

提交回复
热议问题