Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Switching Css based on browser being used

Status
Not open for further replies.

danjapro

Programmer
Aug 27, 2004
54
US
Does anyone know of a javascript or some coding that allows you to switch style sheets based on the borowser being used.

I tried this script and it does not work.


<SCRIPT LANGUAGE="Javascript">
<!-- var bIsIE = navigator.appName == "Microsoft Internet Explorer" var bIsIE4 = bIsIE && navigator.appVersion.indexOf("4.0") > -1
if (bIsIE4)
{ sCSS = '<LINK REL="stylesheet" TYPE="text/css" HREF="nfi2.css">' }
else
{
if (bIsNS)
{ sCSS = '<LINK REL="stylesheet" TYPE="text/css" HREF="nfi2mo.css">' } }
document.write(sCSS) file://-->
</SCRIPT>
 
Code:
<html>
<head>
<link rel="stylesheet" href="default.css" type="text/css" name="styles" id="styles">
<script type="text/javascript">
<!--

// Test for IE
var ie = (navigator.appName == "Microsoft Internet Explorer";

// Test for 4.0 or higher
var ie4 = (ie && parseFloat(navigator.appVersion) >= 4)

// Get style sheet
var sheet = document.getElementById("styles");

if (ie4)
    sheet.href = "nfi2.css";
else if (ie)
    sheet.href = "nfi2mo.css";
else
    sheet.href = "notie.css";

// -->
</script>

--Chessbot

"See the TURTLE of enormous girth!"
-- Stephen King, The Dark Tower series
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top