spacer
Yehuda Shiran December 10, 2000
Two-Way Browser-Independent Scripting
Tips: December 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

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

You should know by now how to detect the browser type. See tip 001125 if you don't. But if your code is browser-independent between Netscape 6 and Internet Explorer, you can drop one of the three ifs. Let's take an example:

if (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:

function handleClick() {
  if (document.getElementById) {
    document.getElementById("foo").style.left = 200;
    document.getElementById("foo").style.top = 100;
    document.getElementById("foo").style.visibility = "visible";
  }
  else if (document.layers) {
    document.layers.foo.left = 200;
    document.layers.foo.top = 100;
    document.layers.foo.visibility = "visible"
  }
  else {
    document.write("Unrecognized Browser Detected");
  }
}


People who read this tip also read these tips:

Look for similar tips by subject:

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