方法一: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;
}