js 判断是否为IE浏览器

条件注释,不适用于IE10及以上版本,无效果

<!--[if IE]>
(~ ̄▽ ̄)~
<![endif]-->

所以只能使用js判断

适用于所有大于ie 6版本的浏览器(IE7、8、9、10等),包括Edge浏览器

    <script>
        function isIE () {
            var userAgent = navigator.userAgent.toLowerCase();
            return (userAgent.indexOf('msie') != -1 || userAgent.indexOf('trident') != -1 || userAgent.indexOf("edge") != -1) ? true : false;
        }
        if(isIE()){
            console.log(1);
        }
    </script>

参考:

https://stackoverflow.com/questions/13785587/if-ie-not-working

https://www.cnblogs.com/garfieldzhong/p/5815187.html

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注




Enter Captcha Here :