Andreas Ramos andreas.com
andreas.com | Blog | Web | Jobs | FAQs | Stuff | Me | Work




 

FAQ: CSS Browser 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...> 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>




andreas at Twitter   andreas' blog   andreas' Newsletter   andreas' Page at Facebook   andreas' Fan Page at Facebook   andreas' channel on Youtube   andreas at LinkedIn   Bookmark and share


web | jobs | FAQs | stuff | me | work | sitemap | © 1994-2010 andreas.com