zoukankan      html  css  js  c++  java
  • 封装判断浏览器是否是IE浏览器

    最近需求中,IE浏览器需要做一些特殊处理,所以封装了一个判断是否是IE浏览器的方法。

    // 获取浏览器内核,通过内核判断
    export const detectIE = () => {
      // 获取浏览器信息
      const ua = window.navigator.userAgent;
    
      // MSIE内核
      const msie = ua.indexOf('MSIE ');
      if (msie > 0) {
        return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
      }
    
      // Trident(又称为MSHTML) 代表:Internet Explorer
      const trident = ua.indexOf('Trident/');
      if (trident > 0) {
        const rv = ua.indexOf('rv:');
        return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
      }
    
      // Edge浏览器
      const edge = ua.indexOf('Edge/');
      if (edge > 0) {
        return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
      }
    
      return false;
    };
    // 判断浏览器是否存在
    export const isBrowser = () => typeof window !== 'undefined' && typeof window.document !== 'undefined';
    
    // 导出判断IE浏览器方法
    export const isIE = () => isBrowser && detectIE();
    

    调用:

    import { isIE } from '******';
    
    if(isIE()) {
        // to do somthing
    }
    
  • 相关阅读:
    rdlc报表动态生成实例
    动态分页实现
    多文件上传
    文件压缩
    javascript解决中文传递乱码和特殊字符问题
    rdlc报表动态生成公共类
    SQLHelp类
    验证码
    使用bison和yacc制作脚本语言(3)
    C Mingw gcc printf 刷新缓冲行
  • 原文地址:https://www.cnblogs.com/a-cat/p/12963737.html
Copyright © 2011-2022 走看看