Javascript; Browser Detection and Page Redirection
A recent project was developed using Internet Explorer 5.5 as
the browser of choice. Aware of browser incompatibilities,
viewing the web page using three other commonly used browsers,
Internet Explorer 4.0, Netscape Navigator 6.1, and Netscape
Navigator 4.7 revealed some 'distortions'. This was mainly due
to whether or not a particular browser could interpret style
sheets, and if so how the style sheets were interpreted.
It was apparent that the page code either needed to be
downgraded to the 'lowest common denominator' or alternative
versions of the web page were needed for Netscape 6.1, Netscape
4.7, and Internet Explorer 4.0. Therefore, a version optimized
for Netscape 6.1 was created, as well as another version
compatible for both Netscape 4.7 and Internet Explorer 4.0.
(This was before Internet Explorer 6.0 and Netscape 6.2 were
available.)
Review of several current web sites and textbooks on Javascript
presented different approaches to writing script to first detect
a user's browser, and then depending on the browser and version,
to redirect the user to a specific page. In this particular
case, none of the recommendations or solutions were what was
needed. After a good deal of testing and re-testing, the
following script examples were assembled.
Below are five different examples / variations of some
Javascript that is to be placed on a page that is optimized for
Internet Explorer 5.5. These scripts will then automatically
detect the visitor's browser and version, and then automatically
direct the particular browser in one of three directions. They
are;
If a visitor is using Internet Explorer 5.5, to remain on the
current page.
If a visitor is using Netscape 6.1, to be redirected to a page
that has been optimized for Netscape 6.1.
If a visitor is using Internet Explorer 4.0 or Netscape 4.7, to
be redirected to a third page that has been written specifically
for either of these browser versions.
Explanatory discussion follows the script examples.
#1
----------------------------------------------------------------
#2
---------------------------------------------------------------
#3
---------------------------------------------------------------
#4
---------------------------------------------------------------
#5
---------------------------------------------------------------
Any of these five different scripts can be utilized. These have
been compiled after many attempts at using other suggested
scripts that either were too limited, were not applicable to
identifying version 5 and higher browsers, or just did not seem
to work as anticipated.
All these scripts are a series of conditional statements, which
are read by the visitor's browser when the web page 'ie55.htm'
is loaded.
1. The browser reads the first statement and if it is Netscape
6.1, it is redirected to the page written specifically for
Netscape 6.1. If not,
2. The browser reads the next statement and if it is Netscape
4.7, it is redirected to the page written for the 'number 4