Detect Browser then load a specific style sheet

Technorealm. The UK web site design company

Free javascript

[One of a collection of free javascripts from www.technorealm.co.uk]

[One of a collection of free javascripts from www.technorealm.co.uk]


This script allows you to detect which browser your visitor is using, then loads up the correct cascading style sheet to suit. Change the name and paths, of the files ie.css (Internet Explorer) and nn.css (Netscape Navigator) to your own file names.

This script needs to go inside the <HEAD> tags.


<SCRIPT LANGUAGE = "JavaScript">
<!-- 
var browser     = '';
var version     = '';
var entrance    = '';
var cond        = '';
// BROWSER?
if (browser == ''){
if (navigator.appName.indexOf('Microsoft') != -1)
browser = 'IE'
else if (navigator.appName.indexOf('Netscape') != -1)
browser = 'Netscape'
else browser = 'IE';
}
if (version == ''){
version= navigator.appVersion;
paren = version.indexOf('(');
whole_version = navigator.appVersion.substring(0,paren-1);
version         = parseInt(whole_version);
}
if (browser == 'IE' && version >= 4) document.write('<'+'link rel="stylesheet" href="ie.css" />');
if (browser == 'Netscape' && version >= 2.02) document.write('<'+'link rel="stylesheet" href="nn.css" />');
// -->
</SCRIPT>



www.technorealm.co.uk UK Web site design and graphics. A free resources site!