↑
Main Page
MSXML
try {
var oXmlDom = new ActiveXObject(arrSignatures[i]);
return oXmlDom;
} catch (oError) {
//ignore
}
}
throw new Error(“MSXML is not installed on your system.”);
} else if (document.implementation && document.implementation.createDocument) {
var oXmlDom = document.implementation.createDocument(“”,””,null);
return oXmlDom;
} else {
throw new Error(“Your browser doesn’t support an XML DOM object.”);
}
}
The next task is to make Mozilla support the
readyState
property and the
onreadystatechange
event handler. This requires you to make some additional changes to the
Document
class.
First, add a
readyState
property and initialize it to 0.
Document.prototype.readyState = 0;
Next, create an
onreadystatechange
property and assign it the value of
null
:
Document.prototype.onreadystatechange = null;
Whenever the
readyState
property changes, the
onreadystatechange
function must be called. To
facilitate this, it’s best to create a method:
Document.prototype.__changeReadyState__ = function (iReadyState) {
this.readyState = iReadyState;
if (typeof this.onreadystatechange == “function”) {
this.onreadystatechange();
}
};
This method takes the new ready state as an argument and assigns it to the
readyState
property. Be
sure you check that
onreadystatechange
is actually a function before calling it (otherwise, this causes
an error). Because this method shouldn’t be called outside of the
Document
object, it uses the JavaScript
notation for a private method (leading and trailing double underscores).
Internet Explorer ’s XML DOM supports five ready states, but there is no way to mimic all of them for
Mozilla. Really, the only important value for
readyState
is
4
, which indicates that the XML DOM is
457
XML in JavaScript
18_579088 ch15.qxd 3/28/05 11:42 AM Page 457
Free JavaScript Editor
Ajax Editor
©
→