jQuery将Browser-Name添加到css-class中 [英] jQuery to add Browser-Name into css-class

查看:95
本文介绍了jQuery将Browser-Name添加到css-class中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery来检测用户浏览器代理,而不是将浏览器名称作为css类添加到正文中。这与webkit和mozilla的魔法一样......但是msie它失败了 - 但不知道为什么。对于msie我不仅要添加«msie»,还要添加一个使用msie版本号的类(如«msie7»或«msie8»)。

I'm using jQuery to detect the Users Browser-Agent and than add the browser-name as a css-class to the body. This works like magic with webkit and mozilla … but with msie it fails — but don't know why. For msie i also have to add not only the «msie», but also one class with the version-number of the used msie (like «msie7» or «msie8»).

一切正常,只有msie-section没有!

Everything works, only the msie-section does not!

my(full)jQuery-Code:

my (full) jQuery-Code:

    <script type="text/javascript">
<!--
(function($){
    $(function(){

        var $copy = $('div.SPA_printcontact').clone();
        var $body = $('body');

        $copy.insertAfter('#printdate');

        if($.browser.msie) {
            $body.addClass('msie')
            var userAgent = userAgent.substring(0,userAgent.indexOf('.'));
            var version = userAgent;
            $body.addClass('msie' + version)
        }
        if($.browser.webkit) {
            $body.addClass('webkit')
        }
        if($.browser.mozilla) {
            $body.addClass('mozilla')
        }

    });
}(jQuery));
-->
</script>


推荐答案

http://api.jquery.com/jQuery.browser/

尝试使用$ .browser.version获取版本号

Try using $.browser.version to get the version no instead

编辑:这已在jQuery v1.9及更高版本中弃用。请参考下面的汤姆答案。

This has been deprecated in jQuery v1.9 and upwards. Please refer to Tom's answer below.

这篇关于jQuery将Browser-Name添加到css-class中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆