Sunday, September 23, 2012

[JS] Easy way to detach browser

source code
// browser detection
$('html').removeClass('no-js');
$.each($.browser,function(a,b){
    if(a!='version'){
        if(a=='msie'){
            var v=Math.floor($.browser.version);
            $('html').addClass('ie ie'+v);
            for(var i=v;i<=10;i++)if(v<i)$('html').addClass('lt-ie'+i);
        }
        else $('html').addClass(a);
    }
});

example (http://jsfiddle.net/NV5k6/)
<!-- before run js -->
<html class="no-js">
<head>....</head>
<body>....</body>
</html>

<!-- after run js (running on ie8) -->
<html class="ie ie8 lt-ie9 lt-ie10">
<head>....</head>
<body>....</body>
</html>

No comments:

Post a Comment