---
title: "javascript判断浏览器兼容"
author: "825197453"
date: "2010-07-04T17:05:58Z"
tags: []
categories: ["Web前端"]
slug: "javascript"
draft: false
lastmod: "2010-07-04T17:08:15Z"
id: 705366
url: "https://825197453.iteye.com/blog/705366"
---

```
使用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")   
  }   
```