(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 "); Create an XMLHttpRequest object (in versions earlier than IE7); in older IE versions, use var xml = new ActiveXObject (" Msxml2.XMLHTTP ") create an XMLHttpRequest object. In IE7 and non-ie browsers, you can use var xml = new XMLHttpRequest () to create an XMLHttpRequest object.
To create an XMLHttpRequest object, you must consider browser compatibility issues.
Create an XMLHTTPRequest object
By the way, let's take a look at 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, while other browsers [such as Firefox/Safari/Opear] implement it as a local javascript Object ). Next let's take a look at how to use javascript to create it:
Code:
Copy codeThe Code is as follows:
<Script language = "javascript" type = "text/javascript">
<! --
Var xmlhttp;
// Create an XMLHTTPRequest object
Function createXMLHTTPRequest (){
If (window. ActiveXObject) {// determines whether ActiveX controls are supported
Xmlhttp = new ActiveObject ("Microsoft. XMLHTTP"); // create an XMLHTTPRequest object by instantiating a new instance of ActiveXObject
}
Else if (window. XMLHTTPRequest) {// determines whether to implement XMLHTTPRequest as a local javascript Object
Xmlhttp = new XMLHTTPRequest (); // create an instance of XMLHTTPRequest (local javascript Object)
}
}
// -->
</Script>
Js is used to distinguish IE from other browsers and methods between IE6-8.
1. document. all
2 ,!! Window. ActiveXObject;
The usage is as follows:
Copy codeThe 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 ");
}
The following describes how to differentiate IE6, IE7, and IE8:
Copy codeThe Code is as follows:
Var isIE = !! Window. ActiveXObject;
Var isIE6 = isIE &&! Window. XMLHttpRequest;
Var isIE8 = isIE &&!! Document.doc umentMode;
Var isIE7 = isIE &&! IsIE6 &&! IsIE8;
If (isIE ){
If (isIE6 ){
Alert ("ie6 ″);
} Else if (isIE8 ){
Alert ("ie8 ″);
} Else if (isIE7 ){
Alert ("ie7 ″);
}
}
First, we make sure that this browser is IE and has been tested once. If you have doubts about this, you can test it.
I am using it directly here. You can declare them as variables for use. It is said that Firefox will also add the document. all method in the future. Therefore, it is recommended to use the second method, which should be safer.