您的位置:首页 > Web前端 > JavaScript

Javascript--识别IE

2015-12-09 22:33 681 查看
方法一:userAgent特殊字符串:

window
navigator
对象反映了浏览器及其功能信息。firefox的
window.navigator
:

>window.navigator.userAgent
"Mozilla/5.0 (Windows NT 6.3; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0"


IE :

>window.navigator.userAgent
"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.3; WOW64; Trident/7.0; .NET4.0E; .NET4.0C; InfoPath.3; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729; GWX:QUALIFIED)"


其中,IE返回的字符串中,“MSIE”可以作为它的特征值:

if(navigator.userAgent.indexOf("MSIE")!==-1){
//It is IE;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: