spacer

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

home / experts / javascript / column77


Netscape 6, Part VI: Object-Oriented DOCJSLIB 1.2

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

File Architecture

We achieve browser-independence by creating on line a browser-specific API object. This API object supports all DOCJSLIB functions. Currently, we can create four different objects: one for IE4, one for IE5, one for NS4, and one for NS6. Detecting the browser is done once per application, so we need to run a single if-else statement at the beginning of the application. No other if-else statements are needed during the application run itself.

Let's look at the files involved in our scheme. They are all included at the top of the application:


<SCRIPT LANGUAGE="JavaScript" SRC="browserSniffer.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="createTheProperSubClass.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="docjslibSuperClass.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="docjslibIE4SubClass.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="docjslibIE5SubClass.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="docjslibNS4SubClass.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="docjslibNS6SubClass.js"></SCRIPT>

The file browserSniffer.js includes the function browserSniffer() which detects the browser type, and assigns a true/false property for each browser.

The file createTheProperSubClass.js includes the function createTheProperSubClass() which creates on line the proper subclass for the detected browser.

The file docjslibSuperClass.js includes the function docjslibSuperClass() which defines the API functions of the library. These function will be inherited later by the proper browser-specific object.

The file docjslibIE4SubClass.js includes the function docjslibIE4SubClass() which inherits the functions of its superclass, docjslibSuperClass, and defines the rest of the library functions specifically for Internet Explorer 4.x.

The file docjslibIE5SubClass.js includes the function docjslibIE5SubClass() which inherits the functions of its superclass, docjslibSuperClass, and defines the rest of the library functions specifically for Internet Explorer 5.x.

The file docjslibNS4SubClass.js includes the function docjslibNS4SubClass() which inherits the functions of its superclass, docjslibSuperClass, and defines the rest of the library functions specifically for Netscape Navigator 4.x.

The file docjslibNS6SubClass.js includes the function docjslibNS6SubClass() which inherits the functions of its superclass, docjslibSuperClass, and defines the rest of the library functions specifically for Netscape 6.

Next: How to write a browser sniffer

http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

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

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: February 12, 2001
Revised: February 12, 2001

URL: http://www.webreference.com/js/column77/4.html