IE10 and IE11 SCRIPT5 Acess is Denied error when attempting a CORS request using XMLHttpRequest

cors, internet-explorer

Solution

Figured out the reason, it was very odd, and because of some crappy legacy code sitting on the site!

This meta tag existed in the header:

<meta http-equiv="X-UA-Compatible" content="IE=9" />

Which was telling IE to run as IE9, and IE9 has a different mechanism for doing cross-domain requests.

Problem

I'm not using jquery, just vanilla javascript. My site is hosted on a domain, let's say it's example.com When running the following code: ``` var xhr = new XMLHttpRequest(); xhr.open('GET', 'http://www.example2.com', true); ``` I get an error: SCRIPT5: Access is denied This code works fine in other browsers (chrome, safari). Also, this only seems to break when running it on my site. When I run that snipped of code from the IE 11 console, on other sites around the web, the error does not occur. Do I need to set any specific headers on the site that's hosting the script? Or on the site that's loading the script?

Original source