Add Window Load Event Without jQuery

Let’s say that you would like to trigger you code after the page is done loading. Easy, just use jQuery to attach a listener to the ready event (e.g. $(function() { ….}); OR $(document).ready(function() {…}) ). But what if jQuery isn’t loaded yet? Well, here is something that you can try.


function callback() {
    /* your code here */

'attachEvent' in window && window.attachEvent('onload', callback, false);
'addEventListener' in window && window.addEventListener('load', callback, false);

Leave a Reply