IE6的navigator.userAgent输出MSIE 7
通过javascript判断浏览器版本时,一般是通过navigator对象的userAgent或者appVersion属性,但是在xp系统下的IE6,navigator.userAgent和navigator.appVersion尽然会是MSIE 7.0,无语了。XP系统版本为Professional 2002,打了SP3补丁。
以后判断浏览器版本最好还是不要用navigator.userAgent和navigator.appVersion,怪不得今天加载的js通过判断navigator.userAgent后没起作用。
要判断是否为真正的IE6浏览器,有2中方法。
1)通过IE独有的条件注释语句,好在IE6的解析器没出错,源代码如下
<script type="text/javascript">var ie6=false</script> <!--[if lte IE 6]> <script type="text/javascript">alert(navigator.userAgent);ie6 = true</script> <![endif]--> <script type="text/javascript">alert(ie6)</script>
2)通过CSS来判断,注意需要设置文档模型为xhtml,要不css hack不起作用
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><div id="dv" style="position:fixed;_position:absolute;"></div>
<script type="text/javascript">
window.onload=function(){
alert(document.getElementById('dv').style.position)//如果为IE6则会输出absolute,否则输出fixed
}
</script>
相关文章:vmware安装的xp系统IE6浏览器navigator.userAgent尽然是MSIE8
加支付宝好友偷能量挖...
原创文章,转载请注明出处:IE6的navigator.userAgent输出MSIE 7