OLW: Detect Browser Version

#Javascript to detect browsers like #Firefox, #Chrome, #Safari, #InternetExplorer or #Opera can be incredibly useful. We looked around and saw inconsistent results with many implementations, but this one line native implementation slightly modified from StackOverflow proved to be both accurate and fast.

var u=navigator.userAgent, t, m=u.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || []; if(/trident/i.test(m[1])){t=/\brv[ :]+(\d+)/g.exec(u) || []; 'IE '+(t[1] || '')} else if(m[1]==='Chrome' && (t=u.match(/\bOPR\/(\d+)/))!=null){'Opera '+t[1]} else { m=m[2]? [m[1],m[2]]: [navigator.appName, navigator.appVersion, '-?']; if((t= u.match(/version\/(\d+)/i))!= null) m.splice(1, 1, t[1]); m.join(' ')}

Use it when you need to handle browser-specific bugs in any way, or if you want to provide a different experience to users on different browsers.

“Getting on a plane, I told the ticket lady, ‘Send one of my bags to New York, send one to Los Angeles, and send one to Miami.’ She said, ‘We can’t do that!’ I told her, ‘You did it last week!’” – Henny Youngman


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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s