Netscape 6, Part V: DOCJSLIB 1.1: Changes for Netscape 6 - Doc Javascript | WebReference

Netscape 6, Part V: DOCJSLIB 1.1: Changes for Netscape 6 - Doc Javascript


Netscape 6, Part V: DOCJSLIB 1.1

Changes for Netscape 6

DOCJSLIB 1.0 includes three functions:

To adapt getSrc() to Netscape 6 and Internet Explorer 5.x, we need to use document.getElementById instead of document.all and document.id. Here is the old version:

function getSrc(id) {
  if (NS4) {return eval("document." + id + ".document."
    + id + "img.src")}
  else {return eval("document.all." + id + "img.src")}
}

and here is the new version that supports both Netscape 6 and IE5.x:

function getSrc(id) {
  if (NS4) {return eval("document." + id + ".document." +
    id + "img.src")}
  else if (IE4) {return eval("document.all." + id + "img.src")}
  else if (IE5 || N6)
    {return document.getElementById(id + "img").src};
}

Similarly, the old version of setSrc() is:

function setSrc(id, url) {
  if (NS4) {eval("document." + id + ".document." + id +
    "img").src = url}
  else {eval("document.all." + id + "img").src = url}
}

and here is the new version that supports both Netscape 6 and IE5.x:

function setSrc(id, url) {
  if (NS4) {eval("document." + id + ".document." + id +
    "img").src = url}
  else if (IE4) {eval("document.all." + id + "img").src = url}
  else if (IE5 || N6)
    {document.getElementById(id + "img").src = url};

As explained on the previous page, the convention used in DOCJSLIB is that if a DIV element is labeled with a given ID, the ID of the IMG element within the DIV element is a concatenation of ID and the string "img". If the DIV's ID is "foo", for example, the IMG element within it will be labeled "fooimg". This is the reason we search above an IMG element that has an ID of id + "img".

Next: How to use DOCJSLIB to write an application

http://www.internet.com


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

URL: http://www.webreference.com/js/column76/6.html