Support Forum Softcomplex logo
About Us  | Services  | Download  | Order  | Support  | |
| Search | Today's Posts | Stats | Board Rules | Not logged in [ Login | Register ]
go to bottom
Last active: Never

Printable Version | Subscribe | Add to Favourites   Post new thread
Author: Subject: cross browser method to assign the window event handler
tigra
Administrator

Posts: 2049
Registered: 6/17/2002
Location: US, CO
Member Is Offline
posted on 12/5/2007 at 09:54 PM Reply With Quote
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;
}

View User's Profile View All Posts By User U2U Member
Post new thread

Related Links:

Go To Top


Powered by XMB 1.9.1 Nexus
Developed By Aventure Media & The XMB Group © 2002-2004