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

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 diverted to an appropriate message on a simplified web page, or relocated to an alternative section of the site, or be given a simpler script code to interpret. 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 by the use of client-side javascript, and all appropriate functions utilized are highly adjustable with this script.

It should preferably 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 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 hyper link below. The script is using the default settings.

Calling the Init function in this document's HEAD

The prepared parts

Before beginning to integrate the Sniff and Divert Script, there is a few things to prepare.  

The Entry page and NOSCRIPT section

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 poorly designed. Here's where you need the Script, because it knows all relevant features about old and new browsers alike. You'd need to put a portion of the script code in the HEAD section of this document. It should be written in order to not break any browser in any way. Ten year old impossible applications like Netscape Navigator 2 or Internet Explorer 3 should instantly be taken care of and nicely turned away from the site towards the FallBackUponURL, while the remainder should be handled the way you decide with another portion of the script located in a separate script source file. Both the HEAD portion and the source file portion will be dynamically generated by you yourself further down this page.

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 the Entry page with a NOSCRIPT section, as elaborate as you think necessary and appropriate.

The FallBackUponURL

Before beginning to customize the script code, you should know the location for and having prepared an HTML 3.2 web page for dated technologies, which you no longer need to support. That web 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 Locations (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, only when you know exactly which browser technology being at hand. The Script is utilizing methods to deal with the relocation of diverse technologies to specific subsections of the site.

The Script will make the current location change to another location in a subdirectory of the originating 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 would "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 alternate scripts, and yet remaining at the current location. Then we say the mode of the Script is in Script Action mode rather than Relocation mode.

The Ready-Made and Custom Script Source Files

To work, the Script depends on one or two external script source files, and the mandatory of these is ready-made (30 kB) in no need of modifications. There is a hyperlinked document that will bring you info about the ready-made source file.

The second and optional source file, which you are supposed to generate yourself by use of the form below, contains the custom-made parts of the Sniff and Divert Script.

Customizing and testing the script

Now is the time to customize and test the script, and furthermore possibly create the generated script source file CustomScriptFile.js. Further down 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.

General script and site entries settings

You may switch between a rather strict approach and a more permissive one by selecting the adequate option right below. The permissive approach is effectively allowing all browsers access to your site except very old ones like Internet Explorer 3 and Netscape Navigator 2. (Choosing it causes the other restrictions below to be ignored.)

Advanced option: Technical relocation condition for avoiding the fallback location will be var exclusionOption = as a result of the above settings. It should never be higher than 5, which would allow only standards compliant browsers, meaning that for instance Internet Explorer 5 on Windows would be excluded along with most browsers from the 20th century.

The following restrictions apply to the strict approach:

Check this box (checked by default), if browsers not ECMAScript compliant should be diverted to YourFallBackUponURL. (Note that this option triggers the strict approach above.)

Technical script condition for entering the site: var restrictScript = ""

Check this box (unchecked by default), if screens smaller than 800x600 pixels and/or less than 256 colours should be diverted to YourFallBackUponURL.

Technical screen condition for entering the site: var restrictScreen = ""

Check this box (unchecked by default), if browsers not (nearly) complying with CSS1, e.g. Netscape Communicator, should be diverted to YourFallBackUponURL.

Advanced option: Technical style sheets condition for entering the site will be var restrictStyle = . 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.

Deciding on the Script Mode

The default script mode is the Simple Relocation mode, moving the surfing client forward to another location, if only the browser meets the requriements stated above. However, the Sniff and Divert Script comes with several options, adapting the script to the needs of your site.

¬ Simple Relocation mode (default)

With the Simple Relocation mode, the diverting of browsers will work according to the general script and site entries settings (cp. above), and the ready-made script function Relocate bring the accepted browsers onward to yourRegularLocation, i.e. the main section of the site.

Having opted for this mode, you should move down on this page to test and generate the containing code (thereby disregarding the remaining options in the list).

¬ Dividing Relocation mode

With the Dividing Relocation mode, the diverting of browsers will work according to the general script and site entries settings (cp. above), and the ready-made script function Relocate will bring the accepted browsers onward to either yourRegularLocation or yourPrivilegedLocation, depending on the settings right below.

By default DHTML browsers will be targeted to yourRegularLocation, i.e. the main section of the site, but HTML4 standards compliant browsers, like Internet Explorer from version 5 on Mac, version 6 on Windows, Opera from version 7 and Netscape from version 6 and other Gecko based browsers like Firefox, as well as Safari, will all instead be targeted to yourPrivilegedLocation, i.e. a section of the site intended for recent or especially capable technologies.

You may modify and decide on the requirements for which browsers to be targeted to yourPrivilegedLocation in the field below (or else the default settings will hold).

These settings apply only to the Dividing Relocation mode

Modify the relocation condition for yourPrivilegedLocation as seen in the combo boxes. With the first box you lay the basis for the relocation. By default it is required for a browser to be able to present a web page in standards mode. You may either loosen the condition to include other browsers as well, or you may strengthen the condition by aid of the second combo box.

Dynamic HTML is a concept designating integrated so-called dynamic technologies like HTML4, JavaScript/JScript and DOM.

   envir.

Additional conditions: Add one or several extra requirements for yourPrivilegedLocation. For example you may want to reserve this part of the site for computers having access to Java technology and the use of high resolution screens. Then first select java in the drop-down menu, and then also muchspace. Cp. the changes in the grey field.
&& envir.

Technical relocation condition for being targeted to yourPrivilegedLocation will be the following:
var level2Option = "" as a result of the options above. Browsers and/or computer environments not complying will be targeted to yourRegularLocation.

Particular operating system If yourPrivilegedLocation requires the use of a particular operating system, you should state that requirement in the combo box below.
&& envir.

Technical relocation condition for being targeted to yourPrivilegedLocation will also be the following:
var level2AddOS = "" as a result of the option above. Computer operating systems not complying will be targeted to yourRegularLocation.

Having opted for this mode, you should move down on this page to test and generate the containing code (thereby disregarding the remaining options in the list).

¬ Mixed Script Action mode

With the Mixed Script Action mode, the diverting of browsers will work according to the general script and site entries settings (cp. above), then either the script function ScriptAction will apply a script code of your own making, or the ready-made script function Relocate will bring the browsers onward to yourRegularLocation.

By default the action is to relocate browsers not DOM level 1 compliant, e.g. Internet Explorer 4, Opera 4-5, Netscape Communicator 4, to yourRegularLocation, while browsers implementing the document.getElementById method get the tailor-made script.

You may modify the rules for the script action and relocation respectively in the field below (or else the default setting will hold).

This setting applies only to the Mixed Script Action mode

Select the required DOM or script standard in the combo box. Only those browsers meeting the requirement you select will be exposed to the tailor-made script (of your making). Other browsers will be targeted to yourRegularLocation.

exami.

Technical condition for initiating the ScriptAction function will be the following:
exami.

¬ Pure Script Action mode

With the Pure Script Action mode, the diverting of browsers will work according to the general script and site entries settings (cp. above), and the script function ScriptAction will contain a script code of your own making. Combined with the permissive approach conditional script codes could be applied.


You should insert your own tailor-made script commands in the generated script code. By default, script commands for ECMAScript or JavaScript from language version 1.2 (depending on the site entries settings) compliant browsers should be used, and browsers not compliant, will then be diverted to yourFallBackUponURL.

With the Pure Script Action mode and a permissive approach, two tailor-made script codes should be used, the simpler one for JavaScript from language version 1.1, and the other code for ECMAScript.

Testing the settings

Select a browser and system from the drop-down menu and generate the code by pressing "Simulated browser". Then test the code by pressing the red button.

Pretending to be using Generate false values:

Test the textarea's code:

No. I'll reset everything and start all over:

Generating the code portion for the optional CustomScriptFile.js

When you're finished doing some testings above, you may choose to generate the real code, and save it as a plain text file named CustomScriptFile.js by default, but any name is applicable. This file is called in the HEAD and may be placed anywhere in the directory structure.

However, if you'd rather prefer to keep the entire generated code with the Entry page, you should move down on this page (and don't mind the buttons below).

Adding the paths and fine-tuning the script

The paths on your site

Parts of the Sniff and Divert Script code must be put in the actual HTML document, and not only because of the call of the script source file(s), but also because some dated browsers cannot read external script files. In this section you will customize the code to put between the head tags in the document.

Stating the in all modes applied fallback URL

As a consequence of the settings decided on in the former section, some simple browser or computer technologies won't meet any requirements of your site. The location below is where the fallback document resides.

Type a full URL or a relative location path. The default is a path relative to the current location:
http://some.server.domain/[../]

Stating the in some modes applied regular path (disabled if not applicable)

Except for the case of Pure Script Action mode, the browser client might be relocated from the entry page to another site location. The location below is where the main target document resides.

Type a relative path like this, "/MySiteRoot/MyTargetDirectory/", or like this, "../MyTargetDirectory/". The script will assume the file name to be the same as the original name of the relocated file.

If you like to use another file name, you should type it next to the path to make it a complete URL. The default is a relative path to a directory (keeping the file name if any):
http://some.server.domain/[../]

Stating the in some modes applied privileged path (disabled if not applicable)

With the Dividing Relocation mode, particularly fit browser clients will be relocated from the entry page to a so-called privileged site location. The location below is where the privileged target document resides.

Type a relative path like this, "/MySiteRoot/MyTargetDirectory/", or like this, "../MyTargetDirectory/"). The script will assume the file name to be the same as the original name of the relocated file.

If you like to use another file name, you should type it next to the path to make it a complete URL. The default is a relative path to a directory (keeping the file name if any):
http://some.server.domain/[../]

Divert option

The excluded browsers are relocated to YourFallBackUponURL 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 (unchecked initially) 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.

The external script file(s)

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

Type the relative path on your server to this file, but note that the file name is added. Leave the field blank if it's placed in the same directory:
[../]

Check this box (unchecked initially) if you intend to use a CustomScriptFile.js, i.e. parts of the customized script code in an external script source file.

Type the relative path on your server to the CustomScriptFile (if used; cp. above). Type both the directory path and the file name. Leave the left field blank if the file is placed in the same directory:
[../]

Generating the script code portion for the Entry page

The textarea above will contain the script code to be placed in the HEAD section of the Entry page. You may choose to have it surrounded by HTML or XHTML tags.

¬ Generating valid HTML (default)
¬ Generating valid XHTML

| No. I'll start all over:

Initiating the script

Having selected and pasted the generated code (see the form above) in the HEAD section of the entry page the script could be initiated by the use of an event handler, such as onLoad or onClick. The function to call is "Init".

 <BODY onload="Init()">    or    <BUTTON onclick="Init()">

For the case the script will do nothing, i.e. JavaScript is not enabled or the browser hasn't implemented the script language, you would need to provide the web page content within NOSCRIPT tags. Preferably this web page should be written using HTML3.2 or HTML4 Transitional code. To facilitate maintenance of the site, I suggest use of the same code here as on yourRegularLocation:

 <noscript>
    your Web Page Content For Browsers Not JavaScript Enabled
                        </noscript>

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

Valid XHTML 1.0 Transitional

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


top of page