Inspired? No home

XMLHTTPRequest & DOMDocument Object sniffer - cross-browser

Finally I updated my MSXML Parser sniffer to be cross-browser and not only for IE. It now support the XMLHTTPRequest and W3C DOMDocument methods used in Mozilla, Opera and Apple Safari.

Download script here.

What this script does:

XMLClientVer():
- Check if client has MSXML Parser installed.
- Check which version of MSXML Parser is installed.
- If MSXML Parser is not installed, check if the client supports XMLHTTPRequest (Mozilla/Safari/Opera implementation) and W3C DOMDocument (Mozilla and ?).

Example:


// Requires: XMLClientver.js
// Can be found at: http://sleeepyhead81.blogspot.com
var MSXMLParser, mozImp, MSXMLParserVer, W3CDOMDocument, XMLHTTPRequest;
var oXMLClientVer = new XMLClientVer();
// Returns true or false
MSXMLParser = oXMLClientVer.MSXMLParser;
if(MSXMLParser) {
// MSXML Parser is installed
// Get which version of MSXML Parser which is installed.
// Returns number from 1-5.
MSXMLParserVer = oXMLClientVer.MSXMLParserVer;
}
else {
// MSXML Parser is not installed
// Check if XMLHTTPRequest and DOMDocument is supported.
// Used by Mozilla, Opera and Apple Safari.
// All methods returns true or false
mozImp = oXMLClientVer.mozImp;
XMLHTTPRequest = oXMLClientVer.XMLHTTPRequest;
W3CDOMDocument = oXMLClientVer.W3CDOMDocument;
}
oXMLClientVer = null;


This is the script:

function XMLClientVer()
{
//
// Public properties
//


this.MSXMLParser = false;
this.MSXMLParserVer = false;
this.mozImp = false;
this.W3CDOMDocument = false;
this.XMLHTTPRequest = false;

//
// Private implementation details
//


var e = new Error();
var oXML = null;
//var vStr;

// Try to load the most recent version of the MSXML parser;
// if that fails, try to load the next most recent version, and so on.
// Always test using the version dependent PROGID.
var XMLParserList = new Array ( 'Msxml2.DOMDocument.1.0', 'Msxml2.DOMDocument.2.0', 'Msxml2.DOMDocument.3.0', 'Msxml2.DOMDocument.4.0', 'Msxml2.DOMDocument.5.0' )
for ( var i = XMLParserList.length; i>0;i--) {
try {
// Test for MSXML obj
oXML = new ActiveXObject(XMLParserList[i-1]);
oXML = null;
this.MSXMLParserVer = i;
this.MSXMLParser = true;
break;
}
catch(e) {}
}

if(!this.XMLParser) {
try {
if (window.XMLHttpRequest) {
this.mozImp = true;
this.XMLHTTPRequest = true;
}
}
catch(e) {}
try {
if (document.implementation && document.implementation.createDocument) {
this.mozImp = true;
this.W3CDOMDocument = true;
}
}
catch(e) {}
}
}

Written on 25 March 2005.
blog comments powered by Disqus