About This Code
Brief Description:
Testing for browser type
Contributor:
Andrew Jones
Last Modified:
17 Jun 2002
OpenNTF Disclaimer
All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.
Code / Description
The following example tests for the browser type and version. //if an unsupported JavaScript browser is encountered, inform them of our requirements... function nogo() { document.write ( "<FONT SIZE=4>Note: To use this version of SiteCreator, you must use Netscape Navigator 3.01+ or Microsoft Internet Explorer 3.01+." ); }
//redirect the browser to its specific code function go() { href = location.href.toLowerCase(); //compare against lowercase href for ".nsf" pos=href.lastIndexOf ('.nsf', href.length-1); dbPath=href.substring (0, pos+4); winopts = "toolbar=no,location=no,directories=no,status=no,menubar=no, scrollbars=yes,resizable=yes";
//we currently only differentiate between Netscape Navigator & Internet Explorer browsers, but here we could do version-specific things view = ( ver == "nn3" || ver == "nn4" ) ? "/$nn/frameset?OpenDocument&A$nn" : "/$ie/frameset?OpenDocument&A$ie"; //open a new window imgWindow=window.open( dbPath + view,"Frameset", winopts); }
//check for our JavaScript-supported browsers if ( ver == "nn3" || ver == "nn4" || ver == "ie301" || ver == "ie302" || ver == "ie4" ) { go(); location= "/cntlcr.nsf" } else { nogo(); } //--> </SCRIPT>
Usage / Example