Lookery Dev Blog RSS

"Stream of geeky consciousness..." @electromute


Authors
@ckelly@danmil
@dcancel@eliast

Friends


Archive

Oct
15th
Wed
permalink

Executing JavaScript on Page Load

If you want to execute JavaScript on page load, please use jQuery or something else. Simply put, don’t use window.onload. However, if you are you writing a single JavaScript file to be used by others and can’t require jQuery then take a look at domready. This little file is a drop-in for your JS file to make sure your code executes after the page has been loaded.

domready is mostly extracted from jQuery with a snippet from Simon Willison’s addLoadEvent. Mostly my job was to read a few of the nightmarish blog posts from Peter Michaux, Dean Edwards, Diego Perini, etc. Once I really understood the complexity of the problem and how hard it was to figure it all out, I went deep into jQuery for the goodies. Hopefully this saves you some trouble to get the functionality you needed.

Thanks John Resig and jQuery team.

-Elias Torres

Comments (View)
blog comments powered by Disqus