JSON在线解析

提问人:SOJSON用户 提问日期:2019-09-21 14:29 热度:574
问题标签 JavaScript 正则

我看网上判断IE浏览器都是千遍一律的,好多写法都有问题。最好是用正则判断下。

1条回答 我来回答
soゝso| 2019-09-21 14:31

我直接给一段曾经JS里写过的一段代码给你。

//判断ie浏览器的版本
function IEVersion() {
    var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
    var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE
    if (isIE) {
    	//这里取到IE浏览器具体版本号
        var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
        reIE.test(userAgent);
        var fIEVersion = parseFloat(RegExp["$1"]);
        //判断IE是几
        if (fIEVersion !== 9 && fIEVersion !== 10 && fIEVersion !== 8) {
        	//低于IE8 给出提示
            console.log('提示:为了能正常使用,请升级您的浏览器至ie8以上!!');
            var vheight = $(document).height();
            $('body').append("<div id='maskBrowser' style='width:100%; height:" + (vheight) + "px; background-color:#000; position:fixed; top:0; left:0; z-index:100;opacity: 0.38; filter:alpha(opacity=38);-moz-opacity:0.38;-khtml-opacity:0.38;  '></div><div class='browserTip' style='z-index: 999;font-size: 14px; width: 490px; height:110px;margin:0 auto;position: fixed;top:50px;background: #fff;border: 1px solid #eee; border-radius: 5px;'><div class='browserTipContent' style='line-height: 66px;text-align: center;'>提示:为了能正常使用,请升级您的浏览器至ie8以上!!</div><div class='browserTipConfirm' style='text-align: center;width: 50px;height: 20px;background: #008573;cursor: pointer;line-height: 20px; border-radius: 5px;margin-left: 45%;margin-top: 7px;color:#fff;'>确定</div></div>");
        }
    }
    $('.browserTipConfirm').on('click', function () {
        $('#maskBrowser').remove();
        $('.browserTip').fadeOut();
    })
}