The better way of Capability Detection
Saturday, 9. December 2006, 23:44:20
In response to Crisp's post about "capability detection" (and his comment system, that ate most of my messages...):
The goal was to optimize the code provided so the "if" statements were not part of the function anymore.
The code wrapped around the "finally" construct might stand alone, and I'm sure the code could be otherwise shortened, but I think this should work all in all...
The goal was to optimize the code provided so the "if" statements were not part of the function anymore.
The code wrapped around the "finally" construct might stand alone, and I'm sure the code could be otherwise shortened, but I think this should work all in all...
if (!window.XMLHttpRequest)
{
var temp;
var types = [
'MSXML2.XMLHTTP.6.0',
'MSXML2.XMLHTTP.3.0'
];
for (var i = 0; i < types.length; i++)
{
try
{
temp = function(){return new ActiveXObject(types[i])};
void(temp());
}
catch(e) {temp = null;}
finally {if(temp) break;}
}
window.XMLHttpRequest = temp || function(){return undefined};
}










