Skip to content

Instantly share code, notes, and snippets.

@suneo3476
Last active December 18, 2015 14:39
Show Gist options
  • Save suneo3476/5799006 to your computer and use it in GitHub Desktop.
Save suneo3476/5799006 to your computer and use it in GitHub Desktop.
IE6以前とクロスブラウザを実現するXMLHttpRequestのコード。ページに表面的な挙動はない。 (IE6なんて入れるのめんどいし確認などしてない)
<!DOCTYPE HTML5>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<div>This is test for XMLHttpRequest with X-Browser. The page does not have any function.</div>
<script>
if(!window.XMLHttpRequest) {
// Internet Explorer 6
XMLHttpRequest = function () {
var objs = ['MSXML2.XMLHTTP.6.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'];
for ( var i = 0; i < objs.length; i++) {
var obj = objs[i];
try{
return new ActiveXObject(obj);
} catch (ignore) {
}
}
throw new Error('Cannot create XMLHttpRequest object');
}
}
var xhr = new XMLHttpRequest();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment