Created
August 3, 2011 23:24
-
-
Save bryanforbes/1124130 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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