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
»

jQuery Snippets: How to Add/Remove Classes After Delay

In your projects, there can often be instances of wanting to change ...

article image
»

jQuery Snippets: Back to Top Button

One common way to use jQuery is to add a useful and functional ...

article image
»

jQuery .on() Method: the Issue of Dynamically Added Elements

The jQuery .on() method is the recommended way for attaching events ...

article image
»

How to Use jQuery to Test CSS3 Browser Support

The tricky thing about using CSS properties (especially newer ones ...

article image
»

jQuery Snippets: Check/Un-Check All Function

This easy-to-implement jQuery code snippet is super useful, and can ...

article image
»

Useful jQuery Code Snippets for Handling CSS

If you’re not already familiar with code snippets, they are ...

article image
»

Using Method Chaining in jQuery

Using method chaining in jQuery helps to ensure that your code stays ...

article image
»

jQuery’s .children() Method

Just like in CSS, it’s possible to use jQuery to select the ...

article image
»

jQuery’s .click() Method

With jQuery, it’s super easy to make something happen as a result ...