One of the problems developers face when writing client-side JavaScript code regards writing code that is compatible with all existing browsers. Internet Explorer in particular has historically raised the most problems because of its non-compliance with the W3C standards.
For example, to attach or detach an event handler for a particular event of an object in Internet Explorer, you need to use attachEvent()
or detachEvent()
. You can easily find examples of working with these functions by googling for “attachevent javascript example”. On the other hand, standards-compliant browsers use addEventListener()
and removeEventListener()
. There are examples with these functions at
http://www.quirksmode.org/js/events_advanced.html
.
The differences don’t stop here! The events themselves sometimes have different names. For example, the event that is raised when a button is clicked is named onclick in Internet Explorer, and is named click
in other browsers. The differences continue...