Skip to content

Instantly share code, notes, and snippets.

@N8-B
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save N8-B/4d60e49acaea9910118f to your computer and use it in GitHub Desktop.
Save N8-B/4d60e49acaea9910118f to your computer and use it in GitHub Desktop.
XMLHttpRequest in IE6
// An alternative implementation to the createXHR function for creating
// an XHR object in all modern browsers as well as emulating IE5 and IE6.
if (window.XMLHttpRequest === undefined) {
window.XMLHttpRequest = function() {
try {
// Use the latest version of the ActiveX object if available
return new ActiveXObject("Msxml2.XMLHTTP.6.0");
}
catch(e1) {
try {
// Otherwise fall back to older version
return new ActiveXObject("Msxml2.XMLHTTP.3.0");
}
catch(e2) {
// But if the older version is not available, throw an error
throw new Error("XMLHttpRequest is not supported");
}
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment