PDA

View Full Version : HELP!! Browser Detection with JScript



djimenez
Feb 3rd, 2005, 08:22 PM
Ok here's the deal. I want to create 2 seperate css files, one for IE and one for Mozilla because I have noticed serious positioning differences between the 2 browsers. I would like to add a javascript that detects which browser the user is using, and then load the correct css file depending on the browser type. Has anyone done anything like this before, or does anyone know of a script I could use that would make this work?

Philip M
Feb 3rd, 2005, 08:37 PM
Well, yes. I think one or two people may have done this before, if only in the privacy of their own homes.

There are a zillion scripts out there. Try for example

http://www.javascriptkit.com/script/cut5.shtml

djimenez
Feb 3rd, 2005, 08:50 PM
Thanks, for the link but that script merely does a redirect to a different HTML page, I am actually more interested in a detection script that would have else if statements regarding which css file to load into one specific html page. I have a vague idea how i would write it but I want to see if this is even a good idea, or if i should try something else.

A1ien51
Feb 3rd, 2005, 09:31 PM
Learn to use google: http://www.google.com/search?hl=en&q=style+sheet+based+on+browser+JavaScript

It helps get your answer asked quicker!

Eric

dlg0351
Feb 3rd, 2005, 10:32 PM
This goes inside the <head></head>

<SCRIPT language="JavaScript">
<!--
var browserName=navigator.appName;
if (browserName=="Netscape")
{
document.write('<link rel="stylesheet" href="ns_stylesheet.css" type="text/css">')
}
else
{
document.write('<link rel="stylesheet" href="ie_stylesheet.css" type="text/css">')
}
//-->
</script>

Philip M
Feb 4th, 2005, 08:39 AM
In fact this question was answered very recently at

http://www.codingforums.com/showthread.php?t=51553

using the IE conditional [if IE]
which is perhaps a simpler solution.