spacer

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

home / experts / javascript / column58


The Doc Dialer, Part 2: A Browser Independent Version

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

Browser-Independent Implementation

One of the classic incompatibilities between Internet Explorer and Netscape Navigator is the way they update DHTML elements. Internet Explorer supports the innerHTML property for several elements, including the SPAN and the DIV. Netscape Navigator, on the other hand, does not support the innerHTML property. The trick to overcome it is by writing to the document property of the DHTML element. The first problem in implementing such a write operation is that it does not work while loading the page. You have to write to the DHTML element only after the page is fully loaded. To do that, we define an event handler, onload():

onload = start;

And start() just writes a welcome message to the phone display:

function start() {
  outputStringToDisplay(welcomeStr);
}

The other problem is that when you write to the DHTML in Netscape Navigator, you completely blank the other attributes of the DHTML, like its frame, its background color, etc. The solution we use here was to embrace a SPAN element within a DIV element:


<DIV ID="displayID" STYLE="position: absolute">
  <SPAN ID="foundSoFar" STYLE="position: absolute; border:
    2px red solid; width: 250">
  </SPAN>
</DIV>

In Internet Explorer, we just change the innerHTML parameter of the inner SPAN, foundSoFar. In Netscape Navigator, we refer to the outer DIV as the DHTML element, and write the SPAN element every time from scratch. Thus, we need to write the border and color specifications, for example, every time:


function outputStringToDisplay(str) {
  if (nameCode == 2) {
    with (document.displayID.document) {
      open();
      str = '<SPAN STYLE="position: absolute; border: 2px red solid;
        width: 235">' + str + '</SPAN>';
      write(str);
      close();
    }
  }
  else {
    document.all.foundSoFar.innerHTML = str;
  }
}

Again, notice how Internet Explorer anchors on the inner SPAN foundSoFar element, while Netscape Navigator anchors around the outer DIV displayID element.

Next: The code

http://www.internet.com

Produced by Yehuda Shiran and Tomer Shiran

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


Created: February 28, 2000
Revised: April 26, 2000

URL: http://www.webreference.com/js/column58/10.html