Browser sniffing cripples menu on MSNBC

Sigh. It is recommended, oft-hyped, recognised-years-ago best practise to avoid browser sniffing and test for objects instead. So why can't a major site like http://www.msnbc.msn.com/ get it right? You'd think a site that large has someone who KNOWS JavaScript (as opposed to cuts and pastes a free script from somewhere..)

Think again. The menu is broken because they say



if (nm_nIE){

if (oP.currentStyle.styleFloat!="none"){

this.xP=oP.offsetLeft;this.yP=oP.offsetTop;break;

}}

(Wrapped and tabbed slightly for readability)

Now, I have never heard of the HTMLElement.currentStyle property and neither has Opera. This causes an error that stops the script. Turns out it is an IE only extension (the standard way is to use the getComputedStyle() function).

Now, it would be so simple, elegant and future-proof to replace the browser sniffer

if (nm_nIE){

with a cleaner object detection:

if (oP.currentStyle){

Translation: rather than saying "if this browser is IE" you can say "if this browser knows about currentStyle". Well, that is apparently not 1999 enough for the coders at MSNBC..

Advertisements

2 thoughts on “Browser sniffing cripples menu on MSNBC

  1. I haven't looked at that but the reason probably is that FireFox runs a whole different part of the script. That is the cost of identifying as IE and supporting document.all, I still think it fixes more sites than it breaks to do so.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s