Best Way to Detecting Internet Explorer Versions Date: October 13, 2008  Tags: javascript    Comments(2)

I've seen a detecting code when I was looking over developer pages of IE8: function getInternetExplorerVersion() { var rv = -1; // Return value assumes failure if (navigator.appName == 'Microsoft Internet Explorer') { var ua = navigator.userAgent; var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); if (re.exec(ua) != null) rv = parseFloat( RegExp.$1 ); } return rv; } I think that there are lots of better ways to detecting browser version.Here is my one-line solution; var IEVersion = /msie/i.test(navigator.userAgent) && parseInt(navigator.userAgent.match(/ie (\d)/i)[1]) || -1 We can use it to get Firefox version with some modifying; /firefox/i.test(navigator.userAgent) && parseInt(navigator.userAgent.match(/firefox\/(\d)/i)[1]) || -1 As you see, test method of regular expressions is really useful, I had seen this technique at Hakan Bilgin's awesome extend.js library firstly.   


Comments:

Paul Irish — October 16, 2008

http://dean.edwards.name/weblog/2007/03/sniff/

Azer — October 17, 2008

Thanks Paul, good trick.

Leave Comment

Name:
E-Mail: (Will be not published)
Website:
Type>

BROWSE BY TAGS

 android (1)  appengine (1)  cherrypy (4)  comet (7)  debugging (1)  django (3)  greasemonkey (1)  javascript (15)  linux (4)  misc (24)  pi (6)  politik (1)  python (7)  sci-fi (1)  security (1)  turbogears (2)  turkce (2)  wsgi (0)

ARCHIVES

December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
May 2008
April 2008
March 2008

RECENT WORK

multiplayerchess.org
pyChessEngine
base64encoder
GTranslate
Pi Library
View All

FLICKR

View All

LINKS

Pandora
Yusuf Arslan
Cloudo&Hakan Bilgin
Selim Cotal
Muhammed Daud
/home/haqen
Serdar Meydanci
Ferruh Mavituna
uic
Christian Wyglendowski
the spanner
john resig
eric's weblog
dustin diaz

A Django site.