Hook a javascript event to page load

If you don’t want to explicitly assign window.onload or use a framework, consider: <script type=”text/javascript”> function startClock(){ //do onload work } if(window.addEventListener) { window.addEventListener(‘load’,startClock,false); //W3C } else { window.attachEvent(‘onload’,startClock); //IE } </script> http://www.quirksmode.org/js/events_advanced.html

window.onload seems to trigger before the DOM is loaded (JavaScript)

At the time window is loaded the body isn’t still loaded therefore you should correct your code in the following manner: <script type=”text/javascript”> window.onload = function(){ window.document.body.onload = doThis; // note removed parentheses }; function doThis() { if (document.getElementById(“myParagraph”)) { alert(“It worked!”); } else { alert(“It failed!”); } } </script> Tested to work in FF/IE/Chrome, … Read more

jQuery resize function doesn’t work on page load

This solution is now deprecated since jQuery 3.0: https://api.jquery.com/bind/#bind-eventType-eventData-handler You’ll want to use: $(document).ready(function() { /* your code */ }); To make something happen onload. If you want something to work onload and onresize, you should do: onResize = function() { /* your code */ } $(document).ready(onResize); $(window).bind(‘resize’, onResize);