用javascript进行浏览器判定

一、检验是否为IE

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>首页</title>

<script> 
if(!+[1,])alert("这是ie浏览器"); 
   else alert("这不是ie浏览器"); 
</script>

</head>
<body>
</body>
</html>

解释:

  • alert([1,])

    IE显示“1,”,非IE显示“1”

  • alert(+[1,])

     +号的作用是把字符串转换为数字,“1,”无法转换为数字,故:

       IE显示“NaN”,非IE显示“1”

  • alert(!+[1,])

    IE显示true,非IE显示0

posted @ 2015-05-20 20:20  非额  阅读(193)  评论(0编辑  收藏  举报