[Javascript] Browser sniffer script question
Michael J. Mahony
igby at mediaone.net
Fri Feb 1 16:42:04 CST 2002
On 1 Feb 2002 at 18:27, Lisa Bradshaw wrote:
> Hi all,
>
> I don't know a whole lot of javascript. I'm mostly a cut-n-paster. I know
> enough to usually be able to tweek a script for my needs. I'm using a
> browser sniffer so I can determine what style sheet to serve up. Problem is,
> I don't know how to translate it fron HTML. Any help would be most
> appreciated. What I want to do is, if the browser is NN4 I want a specific
> style sheet loaded into the parent window. Here's the HTML way to load the
> style sheet:
> <.link rel="stylesheet" type="text/css" href="styles.css"> but how do I do
> it whithin a javascript "if " statement?
> TIA,
> Lisa
Test for the browser type and then insert the stylesheet information with a
document.write command:
function insertStylesheet()
{
if(navigator.appName=="Microsoft Internet Explorer")
{
document.write "<.link rel='stylesheet' type='text/css' href='iestyles.css'>"
}
if(navigator.appName=="Netscape")
{
document.write "<.link rel='stylesheet' type='text/css' href='nsstyles.css'>"
}
}
Just call this function where you would want to insert the style sheet:
<html>
<head>
<title>Document</title>
<script language ="javascript">
insertStylesheet()
</script>
</head>
<body>
blahblahblah
</body>
</html>
Hope that helps.
Michael J. Mahony
Philippians 4:13 --
I can do all things through Him who strengthens me.
More information about the Javascript
mailing list