Home  >  

Cross Browser Testing Cleans Code

Author photo
AddThis Social Bookmark Button

The lack of standardization is the bane of a web developer's life. One can be driven to pulling their hair out trying to remember the differences between browsers and version of browsers. Like everyone else, I'd like not to have to remember all these things or struggle to figure out why a web application doesn't work in one browser but does in others.

Frameworks go along way toward eliminating the problem. The code provided includes tests and branching to handle the idiosyncrasies of browsers—most of the time. There are, however, benefits to testing in several browsers even when they aren't supported browsers. When code fails in one browser, it can help you clean up mistakes that are ignored other browsers. I was reminded of this just the other day.

I was asked to determine why a mouse-out event didn't work in Safari when it worked in IE and Firefox. A tool tip opened as intended but failed to close. Other tool tips on the page worked correctly.

The project uses the Dojo framework and Dojo.byId function to get a reference to the element. Like many such functions provided in other frameworks, it tests whether a string or an object reference is passed. If a string, then getElementById is called and the object reference returned; otherwise, the object reference passed is returned. However, browsers handle loading, parsing, and rendering the page differently.

IE creates a global variable that contains a reference for every DOM element that has an ID with the same name as the ID. As it turns out, Firefox does the same for image tags, and this particular event was on an image tag. I seem to remember older versions of Firefox following IE for all elements but providing a warning in the error console.

It took testing in Safari to discover that the argument intended to be a ID was missing quotes. IE and Firefox converted it to an object reference—one that was not formally declared. It can be argued that this piece of code should have failed in all browsers, but that is another issue.

Testing code in different browsers helps make your code cleaner because is it is more likely errors will be detected.

There are other times browsers handle coding errors or fail to handle them. For example, IE doesn't handle trailing commas in object literals. Can you think of any other coding mistakes that some browsers ignore?

Read more from Lawrence O'Sullivan. Lawrence O'Sullivan's Atom feed

Comments

2 Comments

Priyanka Tiwari said:

hii Lawrence,

nice post.

i was searching this very long back but i didnt get any proper answer for "why to cross check in different browser?"

this post is very helpful for me.Thanks.

But if possible please provide me some easy examples for this cross checking of code.

Its very important for me.

Thanks.

-Priyanka Tiwari

To rescue the web designers from this aching job of testing browser compatibility in different browsers there are few websites which offer this service. On these websites you can check the compatibility of your website in all desired browsers. You can find these websites at http://www.bestpsdtohtml.com/7-awesome-resources-to-test-cross-browser-compatibility-of-your-website/

Leave a comment


Tag Cloud

Poll: Mobile Features

What feature do you use most on your mobile phone?

Vote | View Poll Results | Read Related Blog Entry

Latest Features

  • Overview Purpose of this article The goal of this article is to help you gain a better understanding of the Decorator design pattern.  The Decorator pattern is used to attach additional responsibilities to an object at run time dynamically. Decorators... Continue Reading
  • The proliferation of cellular phones has revolutionized the way we communicate with one another and is the foundation for a more mobile lifestyle. Adobe, a long time player in rich internet applications, wanted to, once again, be an active participant.... Continue Reading
  • Adobe just released public information about AIR 2.0 and added new capabilities that better tie with the operation systems which gives your application more control while increasing performance. The new version will be deployed on Flash player 10 using Flex... Continue Reading
  • WOW! Can you believe it?! Adobe MAX Day 1 is complete, and we have seen a ton of new and exciting announcements. It's hard to think we have more to go. Being a die-hard Flash developer, you can guess which... Continue Reading

Recommended for You

@InsideRIA on Twitter

Archives

  • Or, visit our complete archive.  

About This Site

Welcome to the premiere community site for all things RIA sponsored by O'Reilly Media and Adobe Systems Incorporated.