XMLHTTP 跨浏览器的用法
2008-10-08 18:03
253 查看
//Create a boolean variable to check for a valid Internet Explorer instance.
var xmlhttp = false;
//Check if we are using IE.
try {
//If the Javascript version is greater than 5.
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
alert ("You are using Microsoft Internet Explorer.");
} catch (e) {
//If not, then use the older active x object.
try {
//If we are using Internet Explorer.
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
alert ("You are using Microsoft Internet Explorer");
} catch (E) {
//Else we must be using a non-IE browser.
xmlhttp = false;
}
}
//If we are using a non-IE browser, create a javascript instance of the object.
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
xmlhttp = new XMLHttpRequest();
alert ("You are not using Microsoft Internet Explorer");
}
更简单的方法:
var xmlhttp;
//If, the activexobject is available, we must be using IE.
if (window.ActiveXObject){
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} else {
//Else, we can use the native Javascript handler.
xmlhttp = new XMLHttpRequest();
}
相关文章推荐
- XMLHttpRequest用法介绍
- XmlDocument && XmlHttpRequest 浏览器
- 根据浏览器选择创建XMLHttpRequest对象
- ajax的用法——基于XMLHttpRequest
- XMLHttp 在.Net中的用法
- 不同浏览器创建 XMLHttpRequest 对象的方法
- 以支持多种浏览器的方式创建 XMLHttpRequest 对象
- XMLHTTPRequest简介以及用法加个人真实示例
- XMLHttpRequest用法介绍
- 兼容 IE和FireFox的 XML_HTTP和浏览器共享同一个SessionID
- XMLHttpRequest 及其open()的用法
- 根据浏览器选择创建XMLHttpRequest对象
- AJAX在不同浏览器中XMLHttpRequest对象的生成示例
- Android xml tools 用法 xmlns:tools="http://schemas.android.com/tools"
- Ajax PHP,XMLHttpRequest,浏览器兼容问题
- 为不同浏览器创建XMLHttpRequest对象
- 以支持多种浏览器的方式创建 XMLHttpRequest 对象
- 不同浏览器创建XMLHttpRequest对象
- 转-decorators.xml的用法-http://blog.csdn.net/gavinloo/article/details/7458062