spacer

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

home / experts / javascript / column72


Netscape 6, Part I: Detection and Scripting

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

Cross-Browser Scripting

The introduction of Netscape 6 has worsen the browser-independent scripting situation, at least for a short time. No longer do you have to deal with only two browsers - there are now three major browsers to support. One good old way is to use if statements. You want to make your script as generic as possible, and use if clauses as late as possible. The following script uses this technique. The switchEntries() function is a common event handler for all browsers. The content of switchEntries() is an if statement that executes a different statement for every browser:

<FORM NAME="election">
<SELECT NAME="presidents">
<OPTION NAME="leaving">Al Gore
<OPTION SELECTED>George W. Bush
</SELECT>
<INPUT TYPE="button" VALUE="Switch first option"
  onclick="switchEntries()">
</FORM>
<SCRIPT LANGUAGE="JavaScript">
<!--
function switchEntries() {
  if (document.all) {
    document.election.presidents.item(0).text = 'Bill Clinton';
  }
  else if (document.layers) {
         document.election.presidents[0].text = 'Bill Clinton';
       }
       else if (document.getElementById) {
              document.election.leaving.text = 'Bill Clinton';
            }
}
// -->
</SCRIPT>

Click the button below to see how the first option changes on the fly:

Next: How to avoid Netscape Navigator proprietary features

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: December 4, 2000
Revised: December 4, 2000

URL: http://www.webreference.com/js/column72/4.html