FAQ: CSS Browser Detect

andreas.com FAQ: CSS Detect

CSS is interpreted differently by Microsoft and Netscape browsers. To have a consistent look, you can create two CSS (one for each browser) and use this JavaScript to detect the browser and decide which CSS file to use.

This browser detect JavaScript was written by Brett Burridge. It detects the browser and then writes a <link REL…&gt into your header. To use this, create two CSS files. I named them style-ie.css (for Microsoft) and style-ns.css (for Netscape.)

<head><!– CSS Browser Detect BEGIN –><script language=”JavaScript”><!–browser_version = parseInt(navigator.appVersion);browser_type = navigator.appName;if (browser_type == “Microsoft Internet Explorer” && (browser_version >= 4)) {document.write(“<link REL=’stylesheet’ HREF=’style-ie.css’ TYPE=’text/css’>”);} else if (browser_type == “Netscape” && (browser_version >= 4)) {document.write(“<link REL=’stylesheet’ HREF=’style-ns.css’ TYPE=’text/css’>”);}// –></script><!– CSS Browser Detect END –></head>