jQuery Code Snippet: detect browser type with jQuery

jQuery Code Snippet: detect browser type with jQuery

jQuery Code Snippet: detect browser type with jQuery

With this piece of jQuery code you will be able to check the browser type your visitor is using to visit your website.

Today, there are many different internet browsers … It’s not always easy to optimize your HTML and CSS for all these different browsers. Some internet browsers have their own specific way of parsing and showing your HTML and CSS and slight minor changes will have to be implemented to make sure your website looks the same among all these various browsers.

Normally Internet Explorers are the bugging ones, but in case you’re having other specific issues, you can make use of this jQuery script to target the specific browsers…

$(document).ready(function() {
    // Target Firefox 2 and above
    if ($.browser.mozilla && $.browser.version >= "1.8" ){
        // do something
    }

    // Target Safari
    if( $.browser.safari ){
        // do something
    }

    // Target Chrome
    if( $.browser.chrome){
        // do something
    }

    // Target Camino
    if( $.browser.camino){
        // do something
    }

    // Target Opera
    if( $.browser.opera){
        // do something
    }

    // Target IE6 and below
    if ($.browser.msie && $.browser.version <= 6 ){
        // do something
    }

    // Target anything above IE6
    if ($.browser.msie && $.browser.version > 6){
        // do something
    }
});

Having CSS specific issues?
Read our article about interesting techniques for cross browser CSS.


About the Author

Daan is a Creative-Geek who loves learning and sharing new techniques! Follow him on Twitter to keep up to date with the Creative-Geeks blog and other subjects. Contact him on e-mail : info[at]creative-geeks.com.