tigra
Administrator
Posts: 1920
Registered: 6/17/2002
Location: US, CO
Member Is Offline
|
| posted on 12/5/2007 at 09:54 PM |
|
|
cross browser method to assign the window event handler
With this function multiple event handlers can be assigned to the window event without overwriting each other.
Tested in IE, Firefox, Safari and Opera.
| Code: |
// nicely assigns the window event handlers
// s_event: 'scroll' | 'resize' | 'load'
function f_addEventListener (s_event, f_function) {
if (typeof(f_function) != 'function') // debug
throw(new Error(000, 'Can not assign ' + typeof(f_function) + ' as the event handler.')); // debug
if (document.addEventListener) {
window.addEventListener(s_event, f_function, false);
return;
}
if (window.attachEvent) {
window.attachEvent('on' + s_event, f_function);
return;
}
var f_oldHandler = window['on' + s_event];
if (typeof(f_oldHandler) == 'function') {
window['on' + s_event] = function () {
f_oldHandler();
f_function();
}
return;
}
window['on' + s_event] = f_function;
}
|
|
|
|
|