Jump to content

window.onload


davej

Recommended Posts

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 by davej
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...