Netscape 6, Part VI: Object-Oriented DOCJSLIB 1.2: File Architecture - Doc JavaScript
Netscape 6, Part VI: Object-Oriented DOCJSLIB 1.2
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
Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: February 12, 2001
Revised: February 12, 2001
URL: https://www.webreference.com/js/column77/4.html