A somewhat more generic approach I take is to include this function in every page via a src=blahblah.js assignment (usually just included in a js file along with all my other utility type of functions)
Code:
//////////////////////////////////////////////////////////////////////////////
// addLoadEvent
//
// Add a new function to the windows onload event without
// removing any previous existing functions.
//
// @param func - function name to add to windows.onload
// @return void
//////////////////////////////////////////////////////////////////////////////
function addLoadEvent(func) {
// Save current onload functions
var oldonload = window.onload;
// If this is the first function then assign it to window.onload
// else assign it along with the current functions
if (typeof window.onload != 'function') {
window.onload = func;
}
else {
window.onload = function() {
oldonload();
func();
};
}
}
On each individual page you can add new functions to the body onload event by executing
addLoadEvent(somefunctionname1);
addLoadEvent(somefunctionname2);
.
.
.
etc..
in the the head of each page.
Bookmarks