[Javascript] Organizing onload events

Triche Osborne wdlists at triche-osborne.com
Fri Sep 22 10:06:24 CDT 2006


The more I use unobtrusive methods, the longer my external onload script 
gets and the more often I run into situations where I have events that 
are only required for given pages. Is it standard practice to include 
all of these event attachments in a single file which is loaded for 
every page, regardless of whether the page needs the script (and the 
overhead), or do you tailor the scripts to a given page or section?
	Also, what of scripts that require arguments for the functions called 
by the attached events? Example: an optional popup function that 
requires the pathname, width and height of the image it is to display. 
Since I'm often creating these pages via PHP and want to keep them as 
simple as possible for the end-user to style, I've thought of assigning 
a class="popup" and coded ID to the thumbnail (something like 
id="img12345678-300-400").
	This seems awkward, but so does writing out an associative multi-dim 
array for the page's affected elements. (Since the event may or may not 
need to be attached, depending on whether there is an enlargement 
available, I can't just grab all IMG children within the item DIVs.)
	Am I overlooking a really obvious, simple solution?

Triche Osborne




More information about the Javascript mailing list