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
»

Add Keyboard Shortcut to Anchor Tag Using jQuery

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

Screen Shot 2017-04-23 at 10.15.41 AM
»

How to Use jQuery to Create a Sticky Navigation on Scroll

Creating “sticky” elements is something that can often be ...

article image
»

How to Use jQuery’s Keystroke Methods

jQuery has a few built-in keystroke methods that are all triggered by ...

article image
»

How to Change iFrame Styling Using jQuery

If you’ve ever had the displeasure of working with iFrames, ...

article image
»

How to Use jQuery to Create Blinking Text

Blinking text is one of those cool features that you never actively ...

article image
»

Convert Images to Black and White using jQuery

Converting an image to black and white is no longer a manual event. ...

article image
»

How to Disable Right-Click Menu Using jQuery

There can be dozens of reasons why you may want to disable right ...

article image
»

How to Optimize jQuery Code for Better Performance

jQuery is the most popular client side library, in fact almost every ...

article image
»

Using Head.js to Load All Your JavaScript

In the past few years, client side frameworks/libraries have become ...