Forum Moderators: open
Assuming all the body tags are the same:
<body onload="loadfuncs();">
while I load all the scripts within a separate .js file:
function loadfuncs() {
functionA('a');
functionB('b');
functionB('c');
functionB('d');
}
Question: is it "safe" to implement this global onload event handler for all pages, even those that don't implement any onload script functions (ie, popups, printer-friendly page, etc)?
Another reason I want the body onload function available on every page is because I may need to implement some global onload function in the future. I'm basically trying to plan ahead and future-proof my site.
Thanks for any advice.
Alternatively, you could use a function name, then just create a function that does nothing, such as:
function doNothing(){
//nothing happening here
}
You do want to avoid calling a function that doesn't exist, as that could produce an error message.
I understand what you're saying about using a silent onload function that doesn't exist, but that's not exactly what I'm thinking of.
All my pages will link to the same .js file. This .js file will have about a half dozen function specified which will be executed by stacking them in the .js file:
partial .js file content:
function loadfuncs() {
functionA('a');
functionB('b');
functionC('c');
functionD('d');
functionE('e');
functionF('f');
}
my concern is if I open a page that doesn't use any of those functions, could this lead to problems?
For instance, half my site will use all 6 functions, while the other half will use none, but all the pages contain the following:
<body onload="loadfuncs();">
Is this asking for trouble?