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
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

Browser-Dependent Subclass

You have to define a subclass for each different browser that you want to support. The first action you need to do when defining a subclass is to inherit the properties and the methods of its superclass. You first assign the name of the superclass creation function to a dummy method, inheritFrom:

  this.inheritFrom = docjslibSuperClass;

And then you call this method:

  this.inheritFrom();

By now, the subclass inherited the superclass' methods and properties. Now, it's time to define the browser-dependent methods and properties. Generally speaking, you you should also override the superclass' methods and properties if needed. In our case, we just add methods to the subclass. We first assign function names to the methods:

  this.getSrc = getSrcMethod;
  this.setSrc = setSrcMethod;

And then define the functions:

  function getSrcMethod(id) {
    return eval("document.all." + id + "img.src");
  }
  
  function setSrcMethod(id, url) {
    eval("document.all." + id + "img").src = url;
  }

We show here excerpts from the IE4 subclass. Here is its full listing:

function docjslibIE4SubClass() {
  this.inheritFrom = docjslibSuperClass;
  this.inheritFrom();
  
  this.getSrc = getSrcMethod;
  this.setSrc = setSrcMethod;

  function getSrcMethod(id) {
    return eval("document.all." + id + "img.src");
  }
  
  function setSrcMethod(id, url) {
    eval("document.all." + id + "img").src = url;
  }
}

Similar subclasses are defined for IE5, NS4, and NS6. See listing of all classes later in this column.

Next: How to write an application using DOCJSLIB 1.2

http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

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

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint


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/8.html