Skip to content

Instantly share code, notes, and snippets.

@bryanforbes
Created August 3, 2011 23:24
Show Gist options
  • Select an option

  • Save bryanforbes/1124130 to your computer and use it in GitHub Desktop.

Select an option

Save bryanforbes/1124130 to your computer and use it in GitHub Desktop.
has.add("activex", typeof ActiveXObject != "undefined");
getXhr = function(){
throw new Error("XMLHttpRequest is unavailable");
};
if(has("native-xhr") && !has("dojo-force-activex-xhr")){
getXhr = function(){
return new XMLHttpRequest();
};
}else if(has("activex")){
var XMLHTTP_PROGIDS = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP'], progid,
_getXhr = function(){
return new ActiveXObject(progid);
};
i = 0;
// if in the browser an old IE; find an xhr
while(i<2){
try{
progid = XMLHTTP_PROGIDS[i++];
if(new ActiveXObject(progid)){
// this progid works; therefore, use it from now on
getXhr = _getXhr;
break;
}
}catch(e){
// squelch; we're just trying to find a good ActiveX progid
// if they all fail, then progid ends up as the last attempt and that will signal the error
// the first time the client actually tries to exec an xhr
}
}
}
req.getXhr = getXhr;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment