Check Browser Version in jQuery

Need to check if your users are using a “supported” browser for your site? Don’t like how jQuery handles browser version numbers and chrome. Here’s a bit of javascript to make your life easier by putting version numbers in human readable format. Just update the numbers to match what you consider “supportable” for your site.

<br />
 function is_supported_browser()<br />
 {<br />
 var userAgent = navigator.userAgent.toLowerCase();</p>
<p>// Is this a version of IE?<br />
 if($j.browser.msie)<br />
 {<br />
 userAgent = $j.browser.version;<br />
 version = userAgent.substring(0,userAgent.indexOf('.'));<br />
 if ( version &gt;= 8 ) return true;<br />
 }</p>
<p>// Is this a version of Chrome?<br />
 $j.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase());<br />
 if($j.browser.chrome)<br />
 {<br />
 userAgent = userAgent.substring(userAgent.indexOf('chrome/') +7);<br />
 version = userAgent.substring(0,userAgent.indexOf('.'));<br />
 if (version &gt;= 13) return true;<br />
 }</p>
<p>// Is this a version of Safari?<br />
 if($j.browser.safari)<br />
 {<br />
 userAgent = userAgent.substring(userAgent.indexOf('version/') +8);<br />
 version = userAgent.substring(0,userAgent.indexOf('.'));<br />
 if (version &gt;= 5) return true;<br />
 }</p>
<p>// Is this a version of firefox?<br />
 if($j.browser.mozilla &amp;&amp; navigator.userAgent.toLowerCase().indexOf('firefox') != -1)<br />
 {<br />
 userAgent = userAgent.substring(userAgent.indexOf('firefox/') +8);<br />
 version = userAgent.substring(0,userAgent.indexOf('.'));<br />
 if (version &gt;= '3.6') return true;<br />
 }<br />
 return false;<br />
 }<br />
 

One thought on “Check Browser Version in jQuery

  1. budyk says:

    nice….but we can do it too

    if ($.browser.msie) { if(parseInt($.browser.version) == 8){ // for IE8 $(“html”).addClass(“ie8”); } else if(parseInt($.browser.version) == 7){ // for IE7 $(“html”).addClass(“ie7”); } else if(parseInt($.browser.version) == 6){ // for IE6 $(“html”).addClass(“ie6”); } }

Leave a Reply

Your email address will not be published. Required fields are marked *