`
825197453
  • 浏览: 101053 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

javascript判断浏览器兼容

阅读更多
使用JavaScript创建:
<html>
<head>
<script type="text/javascript">
var xmlhttp

function loadXMLDoc(url)
{
xmlhttp=null
// Mozilla
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
  }
// IE
else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  }
if (xmlhttp!=null)
  {
  xmlhttp.onreadystatechange=state_Change
  xmlhttp.open("GET",url,true)
  xmlhttp.send(null)
  }
else
  {
  alert("你的浏览器不支持 XMLHTTP!")
  }
}

function state_Change()
{
// xmlhttp 加载完成
if (xmlhttp.readyState==4)
  {
  // 处理成功
  if (xmlhttp.status==200)
  {
  alert("XML数据处理成功!")
  document.getElementById('A1').innerHTML=xmlhttp.status
  document.getElementById('A2').innerHTML=xmlhttp.statusText
  document.getElementById('A3').innerHTML=xmlhttp.responseText
  }
  else
  {
  alert("XML检索结果:" + xmlhttp.statusText)
  }
  }
}

</script>
</head>

<body onload="loadXMLDoc('text/note.xml')">
<h2>使用HttpRequest对象</h2>

<p><b>状态:</b>
<span id="A1"></span>
</p>

<p><b>状态描述:</b>
<span id="A2"></span>
</p>

<p><b>返回:</b>
<br><span id="A3"></span>
</p>

</body>
</html>

 

这段判断浏览器兼容问题:
xmlhttp=null  
// 判读是否为Mozilla浏览器   
if (window.XMLHttpRequest)   
  {   
  xmlhttp=new XMLHttpRequest()   
  }   
//判断是否为 IE浏览器   
else if (window.ActiveXObject)   
  {   
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")   
  }   

 

分享到:
评论
1 楼 zhengpingling 2011-05-20  
那chrome呢?怎么判断啊

相关推荐

Global site tag (gtag.js) - Google Analytics