I end up rewriting the code for AJAX-support in IE6 every-time I see it. I think I got it right this time
... or would you gentlemen prefer my last one ...
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); }) );
});
};