AJAX - The Complete Reference

(avery) #1

66 Part I: Core Ideas


var userAgent = navigator.userAgent;
var result = "";
if (activeX === "" && !nativeXHR)
result += "<em>None</em>";

if (nativeXHR)
result += "Native";

if (activeX !== "")
{
activeX = activeX.substring(0,activeX.length-2);
result += " ActiveX [ " + activeX +" ]";
}
var message = "<strong>Browser:</strong> " + userAgent +
"<br /><strong>Supports:</strong> " + result;
return message;
}
</script>
</head>
<body>
<h1>XHR Support Tester</h1>
<hr />
<script type="text/javascript">
document.write(XHRTester());
if (window.XMLHttpRequest)
{
document.write("<h3>Enumerated Properties (and Methods in Some
Browsers)</h3>");
var XHR = new window.XMLHttpRequest();
for (var aprop in XHR)
document.write("<em>XMLHttpRequest</em>."+aprop + "<br />");
}
</script>
</body>
</html>

NNOT EOTE There is some skepticism in the Web development community about the purity of the native
implementation of XHRs in IE7. You’ll note, as shown by the previous example, that things like
object prototypes do not work on XHRs in IE7. In the prerelease versions, even adding instance
properties (expandos) seemed to be problematic, though no longer in the final release.

Because Internet Explorer 7 still supports the legacy ActiveX implementation of
XMLHTTP as well as the native object, you need to be a bit careful. While the benefit of this
side-by-side installation of XML implementations is that older legacy applications using
only ActiveX will not have to be rewritten, scripts may incur unneeded performance hits in
newer versions of IE unless you are careful. When creating an XHR, make sure to always try
native first before invoking ActiveX as it is more efficient, particularly if you are going to be
creating many objects for individual requests. Furthermore, if you play with various
settings in your Internet Explorer 7 browser, you will see that ignoring the legacy ActiveX
Free download pdf