Forum Moderators: open

Message Too Old, No Replies

javascript browser detection that links different css files

         

Terraqueo

7:28 pm on May 16, 2004 (gmt 0)

10+ Year Member



Hi,
I have 3 different .css files to the explorer, mozilla and netscape.
I am able to detect netscape or explorer, but can't succeed to detect mozilla!

my script is like that:

<script language="JavaScript"><!--
if (navigator.appName.substring(0,8) == "Netscape") {
document.writeln('<link rel="STYLESHEET" type="text/css" href="css/style_ns.css">');
}
else {
document.writeln('<link rel="STYLESHEET" type="text/css" href="css/style_ie.css">');
};
</script>

Please, give me a clue!
Thank you

encyclo

8:02 pm on May 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, Terraqueo!

You need to search the string for "Gecko", which is the Mozilla/Netscape 6+ rendering engine. However, be warned, the Mac OSX browser Safari has Gecko in the string, despite not being related to Mozilla.

Terraqueo

8:23 pm on May 16, 2004 (gmt 0)

10+ Year Member



Hi Cyclo, thanks for the welcome answer!

Look I guess I did what you said. My script is now like this:

<script language="JavaScript"><!--
if (navigator.appName.substring(0,8) == "Netscape") {
document.writeln('<link rel="STYLESHEET" type="text/css" href="css/style_ns.css">');
}
else (navigator.appName.substring(0,8) == "Gecko") {
document.writeln('<link rel="STYLESHEET" type="text/css" href="css/style_moz.css">');
}
else {
document.writeln('<link rel="STYLESHEET" type="text/css" href="css/style_ie.css">');
};
</script>

It works to find Mozilla now, but don't know why messes up with explorer.

Do you know why?