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.
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
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=" "></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.
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.
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.
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.
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.
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.
© 2001-2004 The Script is FREE FOR USE if author info is provided.