Javascript判断浏览器类型

2018-03-30 15:38 By "Powerless" 3605 0 3

//判断当前浏览类型
function BrowserType()
{
    var text = '未知浏览器';
    var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
    var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器
    var isIE = userAgent.indexOf("Trident") > -1; //判断是否IE浏览器
    var isEdge = userAgent.indexOf("Edge") > -1; //判断是否Edge浏览器
    var isFF = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器
    var isSafari = userAgent.indexOf("Safari") > -1; //判断是否Safari浏览器
    var isChrome = userAgent.indexOf("Chrome") > -1; //判断Chrome浏览器
    if (isIE){ text = 'IE浏览器';}
    if (isFF) { text = 'Firefox浏览器';}
    if (isOpera) { text = 'Opera浏览器';}
    if (isSafari) { text = 'Safari浏览器';}
    if (isChrome) { text = 'Chrome浏览器';}
    if (isEdge) { text = 'Edge浏览器';}
    return text;
}

评 论

View in WeChat

Others Discussion

  • 初识七层、五层、四层网络协议
    Posted on 2021-04-09 16:52
  • 投票通过,PHP 8 确认引入 Union Types 2.0
    Posted on 2019-11-18 22:22
  • Linux工具 - NM目标文件格式分析
    Posted on 2019-04-24 10:29
  • PHP扩展安装
    Posted on 2019-06-24 11:28
  • Redis各种数据类型的使用场景举例分析【三】
    Posted on 2018-11-22 17:00
  • ACID原则
    Posted on 2020-12-17 16:36
  • PHP7不兼容性
    Posted on 2018-03-07 15:59
  • MySQL分组
    Posted on 2019-11-18 14:00