how to improve your browser sniffing, NBC style

One of the nice things about browser.js is that to maintain it, we need a "web code microscope" – a tool that zooms in on broken code and notifies us of any changes. And sometimes, looking at the microscopic changes and seeing sites change for the better is indeed a positive sight.

One such minor change just occurred at NBC, where browser sniffing used to break video playback in Opera. Investigating the change, we see that NBC has radically simplified and (IMO) improved their browser sniffing.

They used to include a .js file named direct.js which is no longer linked to (though still on the server), instead we have a new file indirect.js. Among other changes, this method:

this.browserDetection = function() 
{ 
var result = new Object(); 

var data = navigator.userAgent; 

if (data.indexOf("MSIE") != -1) 
result.app = "MSIE"; 
if (data.indexOf("Firefox") != -1) 
result.app = "Firefox"; 
if (data.indexOf("Safari") != -1) 
result.app = "Safari"; 

var index = data.indexOf(result.app); 
if (index == -1) 
return; 

// All other browsers we're concerned with, the version is AFTER the browser name... 
if (result.app != "Safari") { 
result.version = parseFloat(data.substring(index + (result.app.length + 1) )); 
} else { 
// why is safari such a pain? 
var startString = "Version/" 
var start = data.indexOf(startString); 
result.version = parseFloat(data.substring(start + startString.length, index)); 
} 
return result; 
}

was replaced by

this.browserDetection = function() 
{ 
var result = new Object(); 
return result; 
}

That's a terrific improvement. Please help the web by copying NBC-style browser sniffing into all your future projects! 😉

Advertisements

18 thoughts on “how to improve your browser sniffing, NBC style

  1. Originally posted by lucideer:

    Brilliant!Can we coin a new verb perhaps – NBC your site. This could be turned into a campaign…

    +1. And, NBC can also stand for "No Browser-Sniffing Crap/Code".

  2. Originally posted by hallvors:

    (Actually, there is an MSNBC patch already. Does it fail for you with browser.js enabled? We might have to update the site patch..)

    MSNBC videos still don't work with browser.js enabled and the default Opera identification. Only works as Firefox or IE for me. :awww:

  3. Originally posted by d4rkn1ght:

    MSNBC videos still don't work with browser.js enabled and the default Opera identification

    Dear impatient Sir, please wait until Ola gets to work and ships a new browser.js file for you. I guess he will release the fix today so you could almost hold your breath waiting 🙂

  4. Originally posted by ouzoWTF:

    Originally posted by hallvors:

    so you could almost hold your breath waiting

    I wouldnt try this out

    :faint:

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