xmlhttprequest.js (1241B)
1 // browser shim for xmlhttprequest module 2 3 var hasCORS = require('has-cors'); 4 var globalThis = require('./globalThis'); 5 6 module.exports = function (opts) { 7 var xdomain = opts.xdomain; 8 9 // scheme must be same when usign XDomainRequest 10 // http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx 11 var xscheme = opts.xscheme; 12 13 // XDomainRequest has a flow of not sending cookie, therefore it should be disabled as a default. 14 // https://github.com/Automattic/engine.io-client/pull/217 15 var enablesXDR = opts.enablesXDR; 16 17 // XMLHttpRequest can be disabled on IE 18 try { 19 if ('undefined' !== typeof XMLHttpRequest && (!xdomain || hasCORS)) { 20 return new XMLHttpRequest(); 21 } 22 } catch (e) { } 23 24 // Use XDomainRequest for IE8 if enablesXDR is true 25 // because loading bar keeps flashing when using jsonp-polling 26 // https://github.com/yujiosaka/socke.io-ie8-loading-example 27 try { 28 if ('undefined' !== typeof XDomainRequest && !xscheme && enablesXDR) { 29 return new XDomainRequest(); 30 } 31 } catch (e) { } 32 33 if (!xdomain) { 34 try { 35 return new globalThis[['Active'].concat('Object').join('X')]('Microsoft.XMLHTTP'); 36 } catch (e) { } 37 } 38 };