Vue进阶(六十八):JS-判断当前浏览器是否为IE

举报
SHQ5785 发表于 2020/12/29 22:54:34 2020/12/29
【摘要】 H5判断 <!--[if IE 6]>仅IE6可识别<![endif]-->   <!--[if lte IE 6]> IE6及其以下版本可识别<![endif]-->   <!--[if lt IE 6]> IE6以下版本可识别<![endif]-->   <!--[if gte I...

H5判断

   <!--[if IE 6]>仅IE6可识别<![endif]-->
  <!--[if lte IE 6]> IE6及其以下版本可识别<![endif]-->
  <!--[if lt IE 6]> IE6以下版本可识别<![endif]-->
  <!--[if gte IE 6]> IE6及其以上版本可识别<![endif]-->
  <!--[if gt IE 6]> IE6以上版本可识别<![endif]-->
  <!--[if IE]> 所有的IE可识别<![endif]--> <!--[if !IE]><!--> 除IE外都可识别<!--<![endif]-->

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

JS判断

function isIE(){
if (window.navigator.userAgent.indexOf("MSIE")>=1) 
return true; 
else
return false; 
}

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

这个方法,edge浏览器中为false,ie11中为false

function isIE() { //ie?
 if (!!window.ActiveXObject || "ActiveXObject" in window)
  return true;
  else
  return false;
 }

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

这个方法,edge浏览器中为false,ie11为true

function IEVersion() { var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串 var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器 var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器 var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1; if(isIE) { var reIE = new RegExp("MSIE (\\d+\\.\\d+);"); reIE.test(userAgent); var fIEVersion = parseFloat(RegExp["$1"]); if(fIEVersion == 7) { return 7; } else if(fIEVersion == 8) { return 8; } else if(fIEVersion == 9) { return 9; } else if(fIEVersion == 10) { return 10; } else { return 6;//IE版本<=7 } } else if(isEdge) { return 'edge';//edge } else if(isIE11) { return 11; //IE11 }else{ return -1;//不是ie浏览器 } }

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

文章来源: shq5785.blog.csdn.net,作者:No Silver Bullet,版权归原作者所有,如需转载,请联系作者。

原文链接:shq5785.blog.csdn.net/article/details/98772366

推荐

华为开发者空间发布

让每位开发者拥有一台云主机

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。