Cross-browser event handling

Tweet

One of the most important aspects of modern unobtrusive DHTML is dealing with events. An event occurs whenever the user interacts with the page in some way – by clicking a link, moving their mouse or typing on the keyboard for example. JavaScript programmers write code to respond to those events, and attach them to specific parts of the page using event handlers.

Sadly, while the modern set of browsers all provide excellent support for most parts of the W3C’s DOM specification, event handling is the one place where significant differences between Internet Explorer and Mozilla/Safari/Opera still exists. Microsoft are not entirely to blame for this: at the time IE 5 was released, the W3C specification for DOM events had not yet been finalised. Hopefully, IE 7 will support the specification in full in addition to maintaining backwards compatibility with previous versions of IE.

In the meantime, workarounds are needed. Thankfully, there’s plenty of documentation to fill the gap. Todd Ditchendorf recently published two articles on this subject: Equalizing JavaScript Event References across IE and EOMB (Every Other Modern Browser) Part 1: DOM Level 0 Event Handlers and Part 2: Programatically registering Event Handlers. Meanwhile, Scott Andrew’s tried and tested addEvent function has been helping deal with the problem since 2001. PPK’s QuirksMode provides extensive coverage of the various browser event models in existence.

This topic is also covered in detail in Stuart’s upcoming book.

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

  • http://www.lowter.com charmedlover

    I’m awating the arrival of Stuart’s book to read more on these interesting topics. I’m just waiting for it to be released.

  • wei
  • melles

    All my problems vanished with Mike Foster’s excellent x library from cross-browser.com

  • pepe

    mierda

  • Robert

    All browsers these days support online event registration software. That is of course unless you’re using a browser that’s 5-10 years old in which case you probably shouldn’t be on the internet anyway. I find that with registration forms Firefox handles them the best. Internet Explorer runs a close second.