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?

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