[JavaScript] In IE7, when the Internet Explorer requests a local resource, access is denied. [reprint]

Source: Internet
Author: User

Reprinted from: http://www.code-design.cn/article/20100910/2844.aspx

In IE7 and IE8, ifDouble-click the HTML page or drag the HTML static pageGo to IE7 and run the IE 8 browser to view the Ajax effect. When the xhr object calls the open methodAccess is denied access errorThis is because Native XMLHttp [XMLHTTPRequest object] is added to IE7 and IE8. If you create a mlhttprequest object when creating an Ajax object in IE7 + browser, due to security settings problems, access to local resources is not allowed.

IE6 does not support XMLHttpRequest objects, but uses acx to Create Ajax objects. Therefore, double-click and run them or drag them into the browser.Access is denied access error. When IE7 or IE8 uses acx to create an accesskey, access is denied.

There are two solutions to the problem

1. Set browser security.
Click "Tools"-> "Internet Options"-> "advanced" and find "Enable Native XMLHttp Support" under the "Security" node. This option is checked by default, disable it to solve the problem.

2. Determine the activexobject object before creating an Ajax object, and use the activexobject object to create an Ajax object.

-Javascriptvar xhr = false;
If (window. activexobject ){
Try {xhr = new activexobject ("msxml2.xmlhttp. 4.0 ");}
Catch (E1 ){
Try {xhr = new activexobject ("msxml2.xmlhttp ");}
Catch (E2) {xhr = new activexobject ("msxml2.xmlhttp ");}}
}
}
Else if (window. XMLHttpRequest ){
/* Put XMLHttpRequest at the end to create it. In this way, double-click and run it in IE7 and IE8, or drag it to enter the browser for browsing.
Access is denied because acx is used to create an Ajax object */
Xhr = new XMLHttpRequest ();
}

ActuallyWe recommend that you first judge the XMLHTTPRequest object.Because the XMLHTTPRequest object version is higher than acx, the Ajax object error and performance of the higher version are better.

  Because the website will eventually be published externally.And then access through the HTTP protocol, so that there is no possibility of "Double-click to run or drag to enter the browser. The requested resources are accessed through the HTTP protocol.As long as not cross-Origin, NoAccess is denied access error.

If you click "double-click to run or drag to enter the browser" to view the effect, you must use the above method to solve the access is denied access error.

Related Article

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.