在《超实用的Javascript代码段》刚刚测试判断IE浏览器的代码:
if(!+[1,]){
alert("这是IE浏览器");
}else{
alert("这不是IE浏览器");
}
发现我并没有测试出来
对应的IE版本是IE10:
后来自己再找了如何判断是否为IE浏览器浏览器的方法:
方法一:
if(navigator.appName=="Microsoft Internet Explorer"){
console.log("第一种方法判断这是IE浏览器");
}else{
console.log("第一种方法判断不是IE浏览器");
}
方法二:
if(navigator.userAgent.indexOf("MSIE")>=0){
console.log("第二种方法判断这是IE浏览器");
}else{
console.log("第二种方法判断这不是IE浏览器");
}
在IE浏览器下测试如下