X

LATEST #JQUERY NEWS

How to Detect a Browser Using jQuery


Any developer can tell you that code will render differently depending on the browser, which can be a real hindrance to cross-browser compatibility. There are CSS hacks that can be used to determine what browser code is running on, but these can only be used to change styling, not HTML. If you want to dynamically change any HTML in your code based on the browser, you can do so using the following jQuery snippets that utilize the $.browser selector:

$(document).ready(function() {
// For Chrome
if( $.browser.chrome)
{
// insert your code here
}
// For Mozilla Firefox 
if ($.browser.mozilla && $.browser.version >= "1.8" ){ 
// insert your code here 
} 
// For Opera 
if( $.browser.opera) { 
// insert your code here 
}
// For Safari if( $.browser.safari ) { // insert your code here }
// For Internet Explorer versions below 6
if ($.browser.msie && $.browser.version <= 6 ) {
// insert your code here
}
// For IE versions 6+
if ($.browser.msie && $.browser.version > 6) {
// insert your code here
}
});

Recently Published

article image
»

How to Dynamically Trim Text Using jQuery

This easy beginners jQuery tutorial demonstrates how you can use ...

article image
»

jQuery Snippets: Getting the Current Year

Here’s a fun, simple, and incredibly useful jQuery that you can ...

article image
»

jQuery Snippets: How to Conditionally Enable Submit

One easy way to prevent users from submitting an empty form in a ...

article image
»

How to Use Google Analytics with jQuery Mobile

jQuery Mobile is an HTML5 based web-page framework that’s ...

article image
»

jQuery Snippets: Using jQuery to Check All Boxes

When you’ve given your users a ton of┬ácheckbox input fields ...

article image
»

Useful jQuery Code Snippets for Working with Images

Images are an essential part of any website and sometimes working ...

article image
»

How to Use jQuery to Check if Cookies are Enabled

A cookie (not the kind with chocolate chips) is a small piece of data ...

article image
»

A Beginner’s Guide to jQuery’s Selectors

We talk a lot about event methods on this site, but not so much about ...

article image
»

Add Keyboard Shortcut to Anchor Tag Using jQuery

Making a user friendly website can be quite a challenging task. There ...