spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / javascript / domwrapper current pageTo page 2To page 3To page 4To page 5
[next]

A Cross-Browser DOM Document Wrapper

Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

By Nicholas C. Zakas (nicholas@nczonline.net)

Introduction

In my opinion, one of the most useful parts of JavaScript is the DOM Document object. With this object, a developer not only can build a DOM Document from scratch, but also can load a file via HTTP into it. The result is the possibility of having client-side JavaScript being loaded with server-side information. What could possibly be better? That answer is simple: if there was a common interface for the DOM Document between Internet Explorer and Netscape.

This article will focus on creating a single DOM Document interface for developers to use in both Internet Explorer 5.0+ (Windows) and Mozilla (The Mozilla browser itself, or Netscape 6.1+). This interface will use both IE's ActiveX approach as well as Mozilla's standards-compliant approach. Because the IE implementation uses ActiveX technology, this will not work on IE for the Mac.

A Little Background

Developers have access to a full library of XML-related objects through Microsoft's MSXML Parser. Each of these objects is an ActiveX object. You can create a DOM Document in Internet Explorer by doing the following:

var objXMLDOM = new ActiveXObject("Msxml.DOMDocument");

Mozilla follows the W3C's DOM standard (http://www.w3.org/DOM/). As such, you create a DOM Document in the following way:

var objXMLDOM =
document.implementation.createDocument("", "", null);

The interesting thing to note is that because an ActiveX object is compiled code on the client machine (Note: not the client Web browser), you cannot have expando properties. The following will cause an error in IE, but not in Mozilla:

objXMLDOM.myAttribute = "blue";

What this means for us is that if we want to extend one interface to be more compatible with the other, it will have to be the Mozilla interface that is customized to be more compatible with the IE interface.

The Factory

As part of this process, we are going to make a JavaScript factory. A factory is a type of object that serves only as a method to access a group of functions. For instance, the following uses the native JavaScript Date object as a factory:

var bIsValidDate = Date.parse(strDate);

Note that we didn't instantiate a Date object; we just used one of its methods. We will create a factory called jsXML, which will have one method called createDOMDocument(). Let's set up the JavaScript file:

//define factory
function jsXML() { }

//define method
jsXML.createDOMDocument = function() {}

home / programming / javascript / domwrapper current pageTo page 2To page 3To page 4To page 5
[next]

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Symantec Whitepaper: Converging System and Data Protection for Complete Disaster Recovery
Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
  Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Symantec Whitepaper: Comprehensive Backup and Recovery of VMware Virtual Infrastructure
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Fixing MySQL Replication · Firewall Guide: First Steps to Securing the Enterprise · VoxOx Tames the Tumultuous Communications Tangle

Created: June 13, 2002
Revised: June 13, 2002

URL: http://webreference.com/programming/javascript/domwrapper/