Window. activexobject (accept)

Source: Internet
Author: User

(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:

Copy content to clipboard

Code :

<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:

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:

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.