Adding events to DOM Elements in javascript by For IE, Mozilla, Opera browsers
To add events to DOM element Dynamically using javascript needs to write different code for different browsers. Browsers Like Mozilla, Opera support the "W3C DOM Level 2 event binding mechanism" which uses a function on DOM elements called addEventListener.
Following the way to add events to DOM element Dynamically for all browser.
if (window.addEventListener != null)
{ // Method for browsers that support addEventListener, e.g. Firefox, Opera, Safari
window.addEventListener("focus", FocusFunction, true);
window.addEventListener("blur", FocusLostFunction, true);
}
else
{ // e.g. Internet Explorer (also would work on Opera)
window.attachEvent("onfocus", FocusFunction);
document.attachEvent("onfocusout", FocusLostFunction); //focusout only works on document in IE
}
Hope this will help you guys........
Comments
Post a Comment