That silly IE6 XMLHttpRequest thing

JerseyFoo

1/g = g-1
Reaction score
40
I end up rewriting the code for AJAX-support in IE6 every-time I see it. I think I got it right this time :D

PHP:
function tryThis(fn, a, b, c){
	if ( fn instanceof String ) fn = new Function(fn);
	try { return fn(a, b, c); } catch(e){};
	return null;
        // can I be used for anything else?
}

/**/
if (!window.XMLHttpRequest) window.XMLHttpRequest = function(){
		var tester = function(s){ return new ActiveXObject(s); };
		
		return tryThis(tester, 'Msxml2.XMLHTTP.6.0') || tryThis(tester, 'Msxml2.XMLHTTP.3.0') || tryThis(tester, 'Microsoft.XMLHTTP');
};

... or would you gentlemen prefer my last one ...

PHP:
/* JS 1.6 library */

/**/
if (!window.XMLHttpRequest) window.XMLHttpRequest = function(){
		['Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.3.0', 'Microsoft.XMLHTTP'].some(function(e, i, a){ 
			return ( window.XMLHttpRequest = tryThis(function(){ return new ActiveXObject(e); }) );
		});
};
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top