Javascript; Browser Detection and Page Redirection

Written by William J. Tolson

Continued from page 1

3. The browser readsrepparttar next statement and if it is Internet Explorer 4.0, it too is redirected torepparttar 105598 page written forrepparttar 105599 'number 4' version of either Internet Explorer or Netscape Navigator. And lastly,

4. If none ofrepparttar 105600 statements apply,repparttar 105601 browser will remain onrepparttar 105602 same page that containsrepparttar 105603 script and proceed to readrepparttar 105604 remainder ofrepparttar 105605 page.

Next are several observations made after consulting several resources (online and in print) and conducting many 'trial and error' sessions.

Peculiarities encountered that caused difficulties include;

1. Regardingrepparttar 105606 line that identifies a browser's version number

(navigator.appVersion.indexOf(" ") != -1) Internet Explorer; you must use "MSIE 4", not "MSIE 4.0", "4", or "4.0". The same is true whether or not this additional ‘if’ statement, (navigator.appName.indexOf("Internet Explorer") != -1), is included as in #1. Use "MSIE 5" to identify Internet Explorer 5.5. **See below for more about Internet Explorer and version numbers. Version 5.5 does not fall underrepparttar 105607 category of version 5 or higher.

Netscape Navigator; in this statement either "5.0" or "5" will work with Netscape 6.1 resulting in directingrepparttar 105608 browser torepparttar 105609 page optimized for Netscape 6.1. if (navigator.appName.indexOf("Netscape") != -1) { if (navigator.appVersion.indexOf("5.0") != -1) window.location="nn61.htm"; } But in this statement, "5.0" must be used. "5" results in Netscape 4.7 being directed torepparttar 105610 page optimized for Netscape 6.1 instead ofrepparttar 105611 page optimized for Netscape 4.7. The reason is unknown. This peculiarity was discovered through 'trial and error'.

if (navigator.appName.indexOf("Netscape") != -1) { if (navigator.appVersion.indexOf("5.0") == -1) window.location="ienn4.htm"; } ** NOTE: Attempting to separate browsers based upon their version number is not as straight forward as it might seem. The reason is that both Internet Explorer 4.0 and Internet Explorer 5.5 haverepparttar 105612 same version number of 4! Also Netscape 6.1 has a version number of 5! So trying to detect and then select browsers based on version numbers results in confusion. In particular

The version number of '5 and higher' will exclude Internet Explorer 5.5 The version number of '4 and lower' will include Internet Explorer 5.5 The version number of '6 and higher' will exclude Netscape 6.1

2. Regardingrepparttar 105613 line that identifies a browser's name

(" ") != -1)

Internet Explorer; you must use "Internet Explorer", "Microsoft", or "Microsoft Internet Explorer". "MSIE" is not recognized.

3. All of these browsers, Netscape 4.7 and 6.1, and Internet Explorer 4.0 and 5.5, haverepparttar 105614 same code name of Mozilla.

Therefore these browsers can not differentiated based on their code name.


Remember that these scripts are to be placed onrepparttar 105615 page that has been optimized for viewing usingrepparttar 105616 Internet Explorer 5.5 browser.

If a Netscape 6.1 browser is being used,repparttar 105617 visitor is automatically redirected torepparttar 105618 page that has been optimized for Netscape 6.1.

If a Netscape 4.7 browser is being used,repparttar 105619 visitor is automatically redirected torepparttar 105620 page that has been optimized for either Netscape 4.7 or Internet Explorer 4.0.

If an Internet Explorer 4.0 browser is being used,repparttar 105621 visitor is automatically redirected torepparttar 105622 page that has been optimized for either Netscape 4.7 or Internet Explorer 4.0.

If none of these three 'if' conditional statements are true,repparttar 105623 browser will remain onrepparttar 105624 present page and will continue on with interpreting that page, in this caserepparttar 105625 page that has been optimized for Internet Explorer 5.5.

To use these scripts, remember to replacerepparttar 105626 fictitious pages "nn61.htm", "ienn4.htm", and "ie55.htm" with your actual pages. Also if using one of these scripts on a page that is created for viewing using a browser other than IE 5.5, further adjustments will be necessary, as well as, then re-testingrepparttar 105627 script(s).

Remember that some ofrepparttar 105628 other browser types that are in use include, i.e. AOL, Netscape Navigator 3.0 or lower, Internet Explorer 3.0 or lower, Opera (various versions), Web TV, Lynx, Konqueror. All of these are used in small numbers and whether one wants to address each one of these browsers is an individual decision.

There are different web sites that contain statistics on browser usage that can be reviewed. The best source of information onrepparttar 105629 actual browsers that are used to view your web site are your own visitor logs. Check those as they may or may not agree with other published web statistics.

Obviously Intranets are a special environment and one in whichrepparttar 105630 pages must be optimized forrepparttar 105631 particular browser that is in use onrepparttar 105632 Intranet machines. This is a much easier situation to have to contend with.

Unfortunately untilrepparttar 105633 'browser wars' come to an end and an 'acrossrepparttar 105634 board acceptance' ofrepparttar 105635 W3C's guidelines for coding isrepparttar 105636 rule, browser incompatibilities will continue to influence web page construction.

After being a practicing dental specialist for twenty-five years, William J. Tolson became intrigued with the Internet and web page design. Self-taught and initially designing and hand coding his own personal web sites, he now devotes all his time as an independent contractor focusing on web page design, optimization and accessibility for all.

Javascript Basics 01

Written by Lisa Spurlin

Continued from page 1

alert(x) creates an alert that will containrepparttar value defined in variable x (make sure that variable x is defined before calling it)

alert("the number is " + x); -creates an alert that will combine text andrepparttar 105597 value in x.

It Can Do Math Too?

JavaScript wouldn't be much of a programming language if it couldn't do simple math. While there are dozens of complex, built-in math functions, here arerepparttar 105598 basic symbols you'll need to know:

addition + subtraction - multiplication * division / greater than > less than < greater than or equal >= less than or equal <=

What "If" Statements

"If" statements are often used to compare values. Ifrepparttar 105599 statement is true, a set of instructions enclosed in {} executes. Comparisons like this are done usingrepparttar 105600 following symbols:

equals == not equal !=

Inrepparttar 105601 example below, you can see how an "if" statement is used to determine text that displays in an alert window. Copy and pasterepparttar 105602 following script into an HTML page to see it at work.

Notice howrepparttar 105603 instructions for each statement (bothrepparttar 105604 "if" and "else") are enclosed in {}(curly brackets). All curly brackets must have a beginning and ending, just like HTML tags. If a curly bracket is missingrepparttar 105605 JavaScript will return an error, so be sure to proof your code.

________________________________________ This document is provided for informational purposes only, and makes no warranties, either expressed or implied, in this document. Information in this document is subject to change without notice. The entire risk ofrepparttar 105606 use orrepparttar 105607 results ofrepparttar 105608 use of this document remains withrepparttar 105609 user. The example companies, organizations, products, people, and events depicted herein are fictitious. No association with any real company, organization, product, person, or event is intended or should be inferred. Complying with all applicable copyright laws isrepparttar 105610 responsibility ofrepparttar 105611 user. Without limitingrepparttar 105612 rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, wit houtrepparttar 105613 express written permission of

If you believe that any of these documents, related materials or any other content materials are being reproduced or transmitted without permission, please contact:

The names of actual companies and products mentioned herein may berepparttar 105614 trademarks of their respective owners.

(C) Copyright 2002. Lisa Spurlin

    <Back to Page 1 © 2005
Terms of Use