davej Posted June 29, 2013 Share Posted June 29, 2013 (edited) Is there any reason to avoid using a simple-minded assignment of the window.onload event? I see some boilerplate that seems to suggest that here... http://www.htmlshell.com/ <script>function autorun(){}if (window.addEventListener) window.addEventListener("load", autorun, false);else if (window.attachEvent) window.attachEvent("onload", autorun);else window.onload = autorun;</script> Edited June 29, 2013 by davej Link to comment Share on other sites More sharing options...
jeffman Posted June 29, 2013 Share Posted June 29, 2013 It's possible that you could mindlessly plug in a 90s-era 3rd-party library that also binds code to the onload event, in which case its code or your code will be overwritten. But that's not very likely. jQuery provides a very simple tool for this, BTW. The library handles all the if-else stuff internally. But for a simple script where you personally have complete control? It's hard to beat the old-fashioned way. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now