(With apologies for the deja-vous
)
Mac/IE5 doesn't support the addition of event handlers using addEventListener or attachEvent, so is there any way of binding an encapsulated load handler, anything other than window.onload?
Here's what I've currently got. The problem with it is that the final group of browsers are only sensitive to exisiting onload functions if they come before this one:

Mac/IE5 doesn't support the addition of event handlers using addEventListener or attachEvent, so is there any way of binding an encapsulated load handler, anything other than window.onload?
Here's what I've currently got. The problem with it is that the final group of browsers are only sensitive to exisiting onload functions if they come before this one:
Code:
//identify konqueror and opera 7 var kde = (navigator.vendor == 'KDE'); var op7 = /opera[\/ ]7/i.test(navigator.userAgent); //.. gecko, safari and generic //need to exclude konqueror specifically //because it returns a function for window.addEventListener //but window.addEventListener('load' doesn't work if(!kde && typeof window.addEventListener != "undefined") { //setup window listener to call initialising function window.addEventListener('load',onloadFunction,false); } //.. opera 7 else if(op7) { //setup document listener to call initialising function document.addEventListener('load',onloadFunction,false); } //.. windows IE else if(typeof window.attachEvent != "undefined") { //setup window handler to call initialising function window.attachEvent('onload',onloadFunction); } //.. mac/ie, osx/msn and konqueror //or anything else that gets this far else { //if there's an existing onload function if(typeof window.onload == "function") { //store it var currentOnload = onload; //setup handler window.onload = function() { //call it currentOnload(); //call initialising function onloadFunction(); }; } else { //setup handler to call initialising function window.onload = onloadFunction; } } //onload function function onloadFunction() { alert("onload"); }
Comment