JS Cross browser Event tool:
Event Tool Object
var eventutil = {};
Add Event
Eventutil.addevent = function (element,type,handle) {
if (element.addeventlistener) {//dom Event
Element.addeventlistener (Type,handle,false);
}
else if (element.attachevent) {
Element.attachevent ("on" + Type,handle);
}
else {
Element["on" + type] = handle;
}
}
Delete Event
Eventutil.removeevent = function (element,type,handle) {
if (element.removeeventlistener) {//dom Event
Element.removeeventlistener (Type,handle,false);
}
else if (element.detachevent) {
Element.detachevent ("on" + Type,handle);
}
else {
Element["on" + type] = handle;
}
}
Get Event
Eventutil.getevent = function (event) {
return event?event:window.event;
}
Get the current event owning object
Eventutil.gettarget = function (event) {
return Event.targert | | Event.srcelement;
}
Block Browser Default Events
Eventutil.preventdefault = function (event) {\ \
if (Event.preventdefault) {
Event.preventdefault ();
}
else {
Event.returnvalue = false;
}
}
Block event capture or bubbling
Eventutil.stoppropagation = function (event) {
if (event.stoppropagation) {
Event.stoppropagation ();
}
else {
Event.cancelbubble = false;
}
}
JS Event cross-browser processing scheme