Thursday, October 6th, 2005

window.onload Cross Browser Solutions

Category: Editorial

<p>Dean Edwards has been discussing the issues with the onload handler and an issue with it:

The window.onload event is used by programmers to kick-start their web applications. This could be something trivial like animating a menu or something complex like initialising a mail application. The problem is that the onload event fires after all page content has loaded (including images and other binary content). If your page includes lots of images then you may see a noticeable lag before the page becomes active. What we want is a way to determine when the DOM has fully loaded without waiting for all those pesky images to load also.

He discusses solutions the involve:

  • Mozilla’s DOMContentLoaded handler
  • IE’s defer attribute (<script defer=”defer” src=”ie_onload.js” type=”text/javascript”></script>)
  • Conditional Comments (<!–[if IE]><script defer src=”ie_onload.js”></script><![endif]–>)
  • Conditional Compilation (/*@if (@_win32) … */)

Sample Page

I still bet that most people put script tags at the bottom of their body ;)

Related Content:

Posted by Dion Almaer at 10:51 am
Comment here

+++--
3 rating from 5 votes

Comments Here »

Comments feed

Leave a comment

You must be logged in to post a comment.