window.onload example 2: Incorrect usage | WebReference

window.onload example 2: Incorrect usage

window.onload example 2: Incorrect usage

This example uses an external script specified by writing out a script tag with src via document.write. The onload handler is specified using an assignment to window.onload in the same script block where the script tag is written out. This does not work because the init function used to initialize window.onload is not defined until the end of the script block where the document.write('<script...><\/script>') occured.

This example does not work in either Netscape 6/Mozilla or Internet Explorer.