Home  >  Article  >  Web Front-end  >  window.ActiveXObject usage instructions_javascript skills

window.ActiveXObject usage instructions_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:16:441268browse

(window.ActiveXObject) What does it mean?
Solution: Determine whether the browser supports ActiveX controls. If the browser supports ActiveX controls, you can use
var xml=new ActiveXObject("Microsoft.XMLHTTP"); to create an XMLHttpRequest object (this (in versions before IE7); in newer IE versions, you can use var xml=new ActiveXObject("Msxml2.XMLHTTP") to create an XMLHttpRequest object; and in IE7 and non-IE browsers, you can use var xml= new XMLHttpRequest() creates an XMLHttpRequest object.

When creating an XMLHttpRequest object, browser compatibility issues must be taken into consideration

Creating an XMLHTTPRequest object

By the way, speaking of differences, let’s take a look here How to declare (use) it, before using the XMLHTTPRequest object to send requests and process responses, we must use javascript to create an XMLHTTPRequest object. (IE implements XMLHTTPRequest as an ActiveX object, and other browsers [such as Firefox/Safari/Opear] implement it as a native javascript object). Let’s take a look at how to use javascript to create it:

Code:

Copy code Code As follows:






js is used to distinguish Method between IE and other browsers and IE6-8.
1. document.all
2. !!window.ActiveXObject;
The usage method is as follows:

Copy code The code is as follows:
if (document.all){
alert("IE browser");
}else{
alert("Non-IE browser");
}
if (!!window.ActiveXObject){
alert("IE browser");
}else{
alert("non-IE browser" ; Code


The code is as follows:

var isIE=!!window.ActiveXObject; var isIE6=isIE&&!window.XMLHttpRequest;
var isIE8=isIE&& !!document.documentMode;
var isIE7=isIE&&!isIE6&&!isIE8; if (isIE){ if (isIE6){ alert(”ie6″); }else if (isIE8){ alert(”ie8″); }else if (isIE7){
alert(”ie7″);
}
}


First of all, we make sure that the browser is IE and have been tested once. If you have doubts about this, you can test it.
I will use them directly in judgment here. You can also declare them as variables first for use. It is said that Firefox will also add the document.all method in the future, so it is recommended to use the second method, which should be safer.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn