Share on Google+Share on Google+

"jQuery. browser " utility method

In this tutorial, we will discuss about the "jQuery.browser' utility method.

"jQuery. browser " utility method

In this tutorial, we will discuss about the "jQuery.browser' utility method. Using this method you can detect which browser is accessing the page and what is the version of the browser. It contains flags for each of the four most prevalent browser classes (Internet Explorer, Mozilla, Webkit, and Opera) as well as version .


<!DOCTYPE html>
p { color:green; font-weight:bolder; margin:3px 0 0 10px; }
div { color:blue; margin-left:20px; font-size:14px; }
span { color:red; }
<script src="jquery-1.4.2.js"></script>
<p>Browser info:</p>
jQuery.each(jQuery.browser, function(i, val) {
$("<div>" + i + " : <span>" + val + "</span>")
//Alerts "Do stuff for firefox 3" only for firefox 3 browsers.
jQuery.each(jQuery.browser, function(i, val) {
if(i=="mozilla" && jQuery.browser.version.substr(0,3)=="1.9")
alert("Do stuff for firefox 3")
//Set a CSS property to specific browser.
jQuery.each(jQuery.browser, function(i) {
$("#div ul li").css("display","inline");
$("#div ul li").css("display","inline-table");


When we run this code using internet explorer :

When we run this code using Mozilla :

Download Source Code

Click here to see demo



Posted on: August 7, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null