how can I load a different stylesheet for each browser?

liunx

Guest
I'm trying to load different style sheets depending on the browser that's being used. The idea is that since IE and Mozilla don't handle absolute positioning the same (usually off by a few pixels), I need to have one stylesheet for each browser.<br />
<br />
I've tried putting in a standard browser detection script in the head secion of my page, the doing a document.write() to output the line to load the stylesheet, but it doesn't work. even when the javascript does nothing except the document.write line , i get no stylesheet loaded. I guess you can't do that.<br />
<br />
What are the options available to do this, given that a server-side script will make my life more difficult as I can't test it easily.<br />
<br />
Thanks.<!--content-->There are two ways.<br />
The first has a cleaner look, but NS devotees don't like it because<br />
it uses an IE only feature (disabled).<br />
<br />
<LINK REL="stylesheet" TYPE="text/css" HREF=http://www.htmlforums.com/archive/index.php/"...style_ns.css" DISABLED> <br />
<SCRIPT> <br />
if (document.createStyleSheet) <br />
{ <br />
ssheet = '...style_ie.css'; <br />
document.createStyleSheet(ssheet); <br />
} <br />
</SCRIPT> <br />
<br />
OR <br />
<br />
<SCRIPT> <br />
ssheet = 'style_default.css'; <br />
if (navigator.appVersion.indexOf('MSIE') !=-1) <br />
{ <br />
ssheet = '...style_ie.css'; <br />
} <br />
document.write('<LINK REL="stylesheet" TYPE="text/css" HREF=http://www.htmlforums.com/archive/index.php/"'+ssheet+'">'); <br />
</SCRIPT> <br />
<br />
Which you select to use is up you, and the way you like to write your<br />
scripts.<!--content-->
 
Back
Top