spacer
Yehuda Shiran November 27, 2000
Three-Way Browser-Independent Scripting
Tips: November 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans

You should know by now how to detect the browser type. See tip 001125 if you don't. You should also know how to move a and hide DHTML elements. Consult tip 001126 if you don't. Let's combine the two now. The following script first writes out an HTML container tag. A DIV tag in Internet Explorer and Netscape 6, a LAYER tag in Netscape Navigator. The tag is both hidden as well as placed outside the window region (negative coordinates):

if (document.all || document.getElementById) {
  document.write('<DIV ID="foo" STYLE="position:absolute; left:-200; top:-100; visibility:hidden;">This is the IE/N6 foo</DIV>');
}
else if (document.layers) {
  document.write("<LAYER NAME='foo' LEFT=-200 TOP=-100 VISIBILITY=hidden'>This is the NN foo</LAYER>");
}
else {
  document.write("Unrecognized Browser Detected");
}

When clicking here, this page should switch with a new page with the above hidden tag. Once you click the Show Element link on top of that page, the following function is called:

<SCRIPT LANGUAGE="JavaScript">
<!--
function handleClick() {
  if (document.all) {
    document.all.foo.style.left = 200;
    document.all.foo.style.top = 100;
    document.all.foo.style.visibility = "visible";
  }
  else if (document.layers) {
    document.layers.foo.left = 200;
    document.layers.foo.top = 100;
    document.layers.foo.visibility = "visible"
  }
  else if (document.getElementById) {
    document.getElementById("foo").style.left = 200;
    document.getElementById("foo").style.top = 100;
    document.getElementById("foo").style.visibility = "visible";
  }
  else {
    document.write("Unrecognized Browser Detected");
  }
}
// -->
</SCRIPT>


People who read this tip also read these tips:

Look for similar tips by subject:


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Search Engine Optimization: Selecting and Embedding Keywords · Are Google's Language Translation Web Services Ready for Prime Time? · Installing and Using Meeplace, the Business Review CMS
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
IBM DB2 10 for z/OS: Justifying the Upgrade · Living La Vida Colo: Choosing the Right Colocation Facility · FTC Concerns over Social Media Privacy Linger