View Full Version : Anyone good with javascript (browser detection --> css?)

06-17-2007, 11:17 PM
Hi everyone. I don't know if anyone will know the answer to this but I figured I'd try anyway >.<

I am trying to use a browser detection script for my new website but I'm not quite sure how to make it to include Safari in the detection. Can anyone help? Thanks in advance.

Here is what I have so far:

if(-1 != navigator.userAgent.indexOf("MSIE"))
// Internet Explorer
document_write('.. rel="stylesheet" type="text/css" href="ie.css">');
else if (-1 != navigator.userAgent.indexOf("Mozilla"))
// Netscape
document_write('.. rel="stylesheet" type="text/css" href="netscape.css">');
// other
document_write('.. rel="stylesheet" type="text/css" href="other.css">');

06-18-2007, 01:01 AM
IMO you shouldn't rely on javascript serve up a stylesheet. You should be working to make your page appear the same in all browsers by coding properly in the first place.

This browser detect script may be what you want. Just remember JS CAN be disabled so the user wouldn't get your stylesheet.


06-18-2007, 01:07 AM
Well, it's all coded properly...it's just a positioning problem in safari with the CSS. It works perfectly in all other browsers...its just safari that messes up >.<

Thanks for the link, I'll check it out.

Bill Posters
06-18-2007, 07:58 AM
It works perfectly in all other browsers...its just safari that messes up
Then why the need for three stylesheets?
If it does turn out the Safari does need a CSS tweak, there are better ways than using a js-dependent stylesheet.

e.g. (http://thomas.tanreisoftware.com/?p=11)