The onload event

We have used the onload event frequently throughout this book. It is triggered when the user enters your page and all its elements have completed loading. The epidemic of advertising pop-up windows is an example—though not an especially pleasant one—of the onload event handler in action.

Although we’ve shown onload repeatedly, up until now we’ve skipped one important bit of information: what to do when you have multiple things you need to have happen when the page loads. Scripts 9.1 and 9.2 demonstrate how to do this.

Script 9.2. Setting multiple onload attributes using our new addOnload() function.
addOnload(initOne);
						addOnload(initTwo);
						addOnload(initThree);
						function addOnload(newFunction) {
						var oldOnload = window.onload; ...

Get JavaScript and Ajax for the Web: Visual QuickStart Guide, Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.