Same Markup: Writing Cross-Browser Code

Live Code Samples

This page contains live versions of the code samples provided as part of my corresponding blog post. Try running these in multiple browsers and modifying the code to observe various results.

Tony Ross
Program Manager

DON'T: Detect Specific Browsers - Event Registration Example

IE9 Output: attachEvent was used

DO: Feature Detection - Event Registration Example

IE9 Output: addEventListener was used

DO: Behavior Detection - getElementById Example from jQuery

IE9 Output: No workaround was used

DON'T: Assume Unrelated Features - Real-World Example

IE7 Output: postMessage is not supported, using workaround
IE8 Output: Message listener registration FAILED
IE9 Output: Message listener registered successfully

DO: Feature Detection - Test for Unrelated Features Independently

IE7 Output: postMessage is not supported, using workaround
IE8 Output: Message listener registered successfully
IE9 Output: Message listener registered successfully