The Browser and Environment Client-Side Sniff and Divert Script, version 2.4

How to use and apply this script

The purpose

The Script will sniff for old and dated or generally incapable browsers and see to it that these won't be broken by too complex script or hyper text markup code, but instead that the clients be given an appropriate message on a simplified web page, or an alert message, or be diverted to an alternative section of the site. Probably you would like to use fresh technologies, but at the same time not lose visitors just because not everybody updated their browsers or computers in a while. All this can be accomplished seamlessly to no annoyance for the site's visitors by the use of client-side javascript, and all appropriate functions utilized are highly adjustable with this script.

It should be allowed to form part of the site's overall structure. The Script is a great utility for controlling traffic on any site, and especially for webmasters not being able to use server scripts, it or a similar system is almost a necessity. For the Script to work as intended, a few things need to be prepared, but first let's try it out.

What would the Script (default settings) do if initiated right here and now?

If you were to check the source of the current HTML file, you would find that the script code is placed near to the top in the HEAD, having already made your browser go and get all the script data. Now you only have to initiate it, and you can do it by clicking the javascript hyper link below. The script source files are containing the default settings ( -- no tricks!).

Calling the Init  function in this document's HEAD

The prepared parts

The Entry or NOSCRIPT page

A client will enter your site (or a section of it) at an entry point. This is where you should expect any browser to come stumbling in. The page at this primary location in the site's structure must cater for anything, or the site would look amateurish. Here's where you need the Script, because it knows all relevant features about old and new browsers alike. Here's where you put the HEAD script. It is written to not break any browser in any way. Ten year old impossible applications like Netscape Navigator 2 or Internet Explorer 3 will instantly be taken care of and nicely turned away from the site towards the FallBackUponURL, while the remainder will be handled the ways you decide. Put the following code snippet in the HEAD section of the document. It is HTML4 Strict standards compliant. There is also an alternative XHTML compliant version. (The code version number must not be lower than 2.2 to function properly.)

<!-- Javascript sniffing begins. Change the script src calls and yourFallBackUponURL.
  PM Browser and Environment Client-Side Sniff and Divert Script. Code version 2.22 -->
<script type="text/javascript"><!--
function stopError(){return true}; window.onerror = stopError;
// --></script>
<script type="text/javascript" src="uaenvirsniff.js"></script>
<script type="text/javascript" src="CustomScriptFile.js"></script>
<!-- (C) PeEmm 2001-2004 larspeemm@netscape.net This is author info. Please do not remove. -->
<script type="text/javascript"><!--
var fbURL = "yourFallBackUponURL.htm"
function UseStatic(){ window.location.href = fbURL; }
function Relocate(l,d){(l=='HS')? location.replace(d): location = d;}
function Init(){if ((navigator.appName=='Netscape'&&parseInt(navigator.appVersion)<3) || 
    (navigator.userAgent.indexOf('MSIE')!=-1&&parseInt(navigator.appVersion)<4)){UseStatic();} 
    else {(typeof(UseDynamic)!='undefined')? UseDynamic(): UseStatic();}}
// THE SCRIPT ENDS HERE. (C)PM 2001-2004. FREE FOR USE (NOT FOR TRADE). --></script>
<!-- Javascript sniffing ends.  -->

Note that there is one limitation though; the Sniff and Divert Script knows nothing about the circa 5-10% of browsers out there going about the web without javascript made available. Therefore you'd need to prepare this page with a NOSCRIPT section, as elaborate as you think necessary and appropriate.

The FallBackUponURL

Before beginning to install the script code, you should know the location for and having prepared an HTML 3.2 web page for a dated technology, which you (simply put) refrain from supporting. This page are adviced to be one and the same for the whole site, even if the Sniff and Divert Script is used multiple times. As an example, please check the fallback page we use at the PM site.

The Target Directories (if any)

Since the Entry page is accustomed to all sorts of browsers, standards and non-standards alike, it's advicable to keep it simple and save the flashy stuff for subsections of the site, where you exactly know which browser technology to deal with. The Sniff and Divert Script has developed methods to deal with the relocation of diverse technologies to specific subsections. The approach is to subdivide (parts of) the site into a main directory suited for the lion share of the site and an alternative directory.

The alternative pages are there for older or otherwise limited browsers or computer environments, which cannot render modern web pages satisfactory. You should decide on the required conditions for the main (normal) part of the site (easily done by filling out the form below), and then all complying browsers and environments will get the document from a named sub directory of your choosing (e.g. "yourMainPages/doc/"). Environments or browsers, which are limited in scope, such as low resolution screens or Netscape Navigator 4, will get an alternative document from another named sub directory of your choosing (e.g. "yourAlternativePages/alt/").

The script will make the location change to another directory (by default keeping the name of the original file) or to another file in the same directory. It will do this applying either the method location = "SomeURL" or the optional method location.replace("SomeURL"). In the first instance the browser is "moving on" to another location and thereby marking a new entry in the history sequence, compared to the second instance where the browser rather "replace" the current history mark with another.

The Script doesn't make the relocation compulsory, though. It may easily be configured to deal with many kinds of scripts, while remaining at the current location. Then we say the mode of the Script is in ScriptAction mode rather than Relocation mode.

The Ready-Made Script file

To work, the script uses two external script files, of which one is ready-made (29 kB) and doesn't need any modifications. This hyperlinked document will bring you info about this script file. The second external script, you are supposed to generate yourself by use of the form farther below.

Generating the CustomScriptFile.js

Now is the time to create the generated CustomScriptFile.js script source file. At the bottom of this page, you could click a button to have the script code generated already this very minute, but of course you should adapt it to your site's particular needs, which is quickly accomplished by filling out the form.

Recommended package solutions (general script settings)

Approach no. 1: Support DHTML browsers only, and bring alternative pages to browsers not standards compliant (default),
e.g. Netscape Navigator 3, Opera 3 will be diverted to YourFallBackUponURL, but Javascript from language version 1.2 enabled browsers will be targeted to another location, which one depending on whether the browser is standards compliant or not. Internet Explorer from version 5 on Mac, version 6 on Windows, Opera version 6 and Netscape from version 6 and other Gecko based browsers all comply with HTML standards.

Cp. approach no. 4.

Approach no. 2: Support DHTML browsers only, and use no alternative pages,
e.g. Netscape Navigator 3, Opera 3 will be diverted to YourFallBackUponURL, but Javascript from language version 1.2 enabled browsers will be targeted to the main section of the site.
Approach no. 3: Support DHTML browsers only, and use tailor-made script code,
e.g. Netscape Navigator 3, Opera 3 will be diverted to YourFallBackUponURL, but Javascript from language version 1.2 enabled browsers will be exposed to a tailor-made script of your making.
Additional browser support restrictionsThese settings apply to approaches 1-3

If checked, browsers not (nearly) complying with CSS1, e.g. Netscape Communicator 4, will be diverted to YourFallBackUponURL.

Advanced option: Additional technical condition for entering the site will be envir.decimalcss >= . This would be a value ranging from 0 to 2.1 and calculated upon the properties of the style object to return an approximate level of CSS implementation. Changing the number to "1.5" would result in the exclusion of Internet Explorer 4 as well.

If checked, screens smaller than 800x600 pixels and less than 256 colours will be diverted to YourFallBackUponURL.

Additional technical condition for entering the site:

If checked, browsers not java enabled will be diverted to YourFallBackUponURL.

Additional technical condition for entering the site:

Approach no. 4: Support almost all browsers, and bring alternative pages to browsers not standards compliant,
i.e. very old browsers, like Internet Explorer 3, will be diverted to YourFallBackUponURL, but Javascript from language version 1.1 enabled browsers will be targeted to another location, which one depending on whether the browser is standards compliant or not. Internet Explorer from version 5 on Mac, version 6 on Windows, Opera version 6 and Netscape from version 6 and other Gecko based browsers all comply with HTML standards.
Optional fine-tuningThis setting applies only to approaches 1 and 4

Modify the relocation condition for the main location. By selecting an option here, you are effectively redefining what should count as "standards compliant".

Approach no. 5: Support almost all browsers, and bring alternative pages to browsers using dated rendering engines,
i.e. very old browsers, like Internet Explorer 3, will be diverted to YourFallBackUponURL, but Javascript from language version 1.1 enabled browsers will be targeted to another location, which one depending on whether the browser is using DHTML and at least CSS1. Internet Explorer from version 4 is such a browser, but Netscape Communicator is not, and it will therefore be diverted to an alternative location.
Optional fine-tuningThis setting applies only to approach 5

Modify the relocation condition for the main location. By selecting an option here, you are effectively redefining what should count as "dated rendering engines". Dynamic HTML is not a recognised standard, but rather a concept designating HTML4 combined with "dynamic" technologies like JavaScript or JScript.

Approach no. 6: Support almost all browsers, use tailor-made script code for the main section, and bring alternative pages to browsers not (script) standards compliant,
i.e. very old browsers, like Internet Explorer 3, will be diverted to YourFallBackUponURL, but Javascript from language version 1.1 enabled browsers will be targeted to another location or exposed to a tailor-made script of your making, depending on ECMAScript compliance.
Approach no. 7: Support almost all browsers, and use alternative tailor-made script codes,
i.e. very old browsers, like Internet Explorer 3, will be diverted to YourFallBackUponURL, but Javascript from language version 1.1 enabled browsers will be exposed to one out of two tailor-made scripts of your making, depending on ECMAScript compliance.
Alternatives to ECMAScriptThis setting applies only to approaches 6-7

You should insert your script commands in the generated script file. You'd write your own script for ECMAScript compliant browsers by default, and let browsers not fully compliant, get the alternative page or a simpler script code, or the FallBackUponURL.

Decide on the Script language complexity or DOM.

Only those browsers capable of interpreting the language or model you use will be exposed to it. The remainder will get another script of your making or be diverted to another location.
  • NC (proprietary) - using document.layers i.e. Netscape Navigator 4
  • MS (proprietary) - using document.all i.e. Internet Explorer 4-6 and (with spoofing) Opera 5-7
  • ECMAScript (default) - e.g. Netscape from version 4.06, Internet Explorer 4+, Opera 4+, Gecko
  • DOM level 1 HTML - incl. document.getElementById e.g. Internet Explorer 5+, Opera 6+, Gecko
  • DOM level 2 Events, Style, CSS, HTML - e.g. Opera 7 (Events), Gecko browsers (all)

Technical condition for initiating the ScriptAction function will be exami.

Paths and extra settings

Stating the sometimes used main path (disabled if not applicable)

By default the client gets relocated to a chosen directory. Type an absolute path, e.g. "/MySiteRoot/MyTargetDirectory/", or a relative path, e.g. "../MyTargetDirectory/". The script will assume the file name to be the same as the original name of the relocated file. If you're using another file name, you should type it next to the path to make it a complete URL.

The location below is where the main document resides (if relocation to it is used).
Example: http://some.server.domain/[dir]

Technical relocation condition for going to the main location will be envir. as a result of the approach set farther above. This property will make a difference only if also an alternative path is used (cp. below).

Additional option: Add an extra condition for going to the main location. For example you may want to reserve the main directory for American visitors. Then select "newworld" in the drop-down menu. Cp. property names of the envir object in uaenvirsniff.js.
level2Addon = && envir.

Stating the sometimes used alternative path (disabled if not applicable)

Some simple browser or computer technologies won't meet the requirements at your site. If you yet want to have these clients, a solution would be to divert them to an alternative section of it.

The location below is where the alternative document resides (if relocation to it is used).
Example: http://some.server.domain/[dir]

Advanced option: Technical relocation condition for entering the site (i.e. the alternative and/or main location) will be the MozillaToken Sub number exami.appCodeNameSub >= as a result of the approach set farther above. If you change it to "5", only standards compliant browsers will be allowed at the site, meaning that for instance Internet Explorer 5 on Windows would be excluded.

Generate and test

Pretending to be using Generate false values:

When you're finished doing the testings, the generated code should be saved as a plain text file called CustomScriptFile.js or another name of your choosing. This file is called in the HEAD. If you are preparing for several relocations (of different URL:s), you could generate the code for each and every one, give every script file a unique name and collect all script files in the same directory for convenience. Just make sure the matching with the HEAD call is correct.

Test the textarea's code: | No. I'll start all over:

Divert option — The excluded browsers are relocated to YourFallBackUponURL.htm assigned in the document HEAD script. There you'll also find the essential Relocate function, which is at the heart of this script, irrespective of the so-called script mode. By default the Script applies the location = "SomeURL" method, if diverting the client to another location, thereby marking another entry into the history sequence.

Check this box if you'd like the Script to try (not always possible) to apply the location.replace("SomeURL") method instead, thereby causing no extra entry into the history sequence. This would be useful in the case of initiating the script on an onLoad event, then saving the functionality of the Back button.

OK. Let me have the code to use:

Putting everything in store

Right-click and save the most recent edition of the separate javascript source file in a convenient directory. The code version number must not be lower than 2.4 to function properly.
uaenvirsniff.js

Having selected and pasted the generated code (see the form above) in a script source file named "CustomScriptFile.js" or anything you choose, and saved it in a convenient location, there is only the customizing of the primary document (the Entry page) left not to forget. Check the location and name for CustomScriptFile.js and uaenvirsniff.js. Substitute your own link for the faked yourFallBackUponURL.htm relocation link.

To initiate the Script, you could use an event handler, such as onLoad or onClick. The function to call is "Init".

<BODY onLoad="Init()">
<BUTTON onClick="Init()">

 That's it. No more frustrated surfers will choose another website or even send you angry emails.

Valid HTML 4.01!

© 2001-2004 The Script is FREE FOR USE if author info is provided.