Safari <body onload> event doesn't trigger from the back button

后端 未结 5 1245
甜味超标
甜味超标 2021-01-25 16:27

I don\'t seem to be able to get the body onload=\"...\" event to fire in Safari when the page is entered via the back button. It works fine in FF and IE. Is there a Javascript

5条回答
  •  滥情空心
    2021-01-25 16:37

    Rather than using the onload attribute of the tag, you could instead try using the DOM ready event with jQuery, like so:

    $(document).ready(function() {
        // your code here
    });
    

    Or, the shorthand version:

    $(function() {
        // your code here
    });
    

    Even if this doesn't solve your issue with Safari, it's still a good practice in general because it separates your HTML and Javascript into easily discernible parts.

提交回复
热议问题