Cross-browser event handling

By | | JavaScript & CSS

5

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.

Written By:

Simon Willison

Simon is a seasoned Web developer from the UK, currently working in Lawrence, Kansas. He specializes in both client- and server-side development, and recently became a member of the Web Standards project. Visit him at http://simon.incutio.com/, and at Stylish Scripting: SitePoint's DHTML and CSS Blog.

Website
>> More Posts By Simon Willison

 

{ 5 comments }

Robert June 19, 2008 at 1:32 pm

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.

pepe May 5, 2006 at 11:56 pm

mierda

melles April 5, 2005 at 7:57 am

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

wei April 4, 2005 at 8:22 pm
charmedlover April 3, 2005 at 3:22 pm

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.

Comments on this entry are closed.