CHAPTER 8 SCRIPTING IN THE BROWSER 241 (Kids web site)

CHAPTER 8 SCRIPTING IN THE BROWSER 241 Browser Support for the W3C DOM Now that you ve seen the interfaces available in the W3C DOM, let s examine how you can use JavaScript to work with XML data stored in a DOM Document on the client. You can create a DOM Document using an ActiveX object in IE. You can use the following code to create an instance of the MSXML parser: var oDocument =new ActiveXObject(”Microsoft.XMLDOM”); Bear in mind that different versions of IE use different ActiveX objects. Mozilla creates a document using this line: var oDocument =document.implementation.createDocument(”", “”, null); These lines are just the start of the differences between the two major browsers. Given that the DOM implementations in MSXML and Mozilla aren t completely compatible, you need to be careful to develop client-side code suitable for both browsers. You could write code that branches to accommodate each different approach. However, a better solution is to use a wrapper to allow both browsers to exhibit the same JavaScript behaviors. This book includes the xDOM wrapper, written specifically for this chapter. Using the xDOM Wrapper xDOM is a JavaScript library that makes it easier to write cross-browser JavaScript code for client-side manipulation of the DOM. You can find the library in the files xDOM.js and browserDetect.js with your resources. The wrapper needs to use a common method to create documents. It also needs to be able to provide a mechanism for Mozilla to deal with MSXML-specific methods and properties and the application of XSLT stylesheets on the client side. Table 8-3 summarizes the functions available in xDOM.js. Table 8-3. Functions Available in xDOM.js Function Name Description Public xDOM.createDOMDocument() This is the main function in xDOM. It creates a DOM Document. Yes _Moz_Document_loadXML(strXML) An implementation of loadXML() for the Mozilla DOM. You add a method to the Mozilla DOM to call this function. No _Moz_Document_load(strURL) Replaces the Mozilla DOM load() method. You override the existing method on the Mozilla DOM to call this function. No document_onload() A local event handler used to call fireOnLoad() when the document is loaded in Mozilla. No fireOnLoad(oDOMDocument) Checks for a parser error and changes the readyState if required. No Continued
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

Leave a Reply