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:

  • Reduce cross-browser testing issues
    Cross-browser testing can eat up too much time. Here are some tips and tricks to help reduce frustrating cross-browser display issues and shorten the...
  • How to prevent cross-site scripting
    Learn how cross-site scripting, a common Web application attack, operates and what Web users and Web developers can do to protect against it, in this...
  • How to prevent cross-site scripting
    Learn how cross-site scripting, a common Web application attack, operates and what Web users and Web developers can do to protect against it, in this...
  • Deal with cross-site scripting
    Cross-site scripting vulnerabilities are a serious problem in application security. Mike Chapple offers basic information an XSS...
  • Deal with cross-site scripting
    Learn what a cross-site scripting attack is, how it affects Web users and their systems and what developers should do to prevent future security...

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.