View Full Version : javascript to switch style sheet?
electrickeye
16 Apr 2008, 10:04 AM
Due to browser differences, positioning of some divs in my site differ in IE and FF. I don't think there's a way to fix this, so is a there a way to use javascript to switch the external style sheet depending on the detected browser?
Wickham
16 Apr 2008, 12:50 PM
You can use javascript to use a different stylesheet but it's more complicated than using a conditional comment.
You should get your page working properly in Firefox first as that is probably the most standards-compliant browser. Then use a conditional comment in the head section with different styles for IE6 or IE7. These don't use javascript.
See http://www.wickham43.supanet.com/tutorial/generaladvice.html#conditionalcomments
You can also use a completely different stylesheet for IE browsers using the above method if you have lots of different styles to edit or if you want a completely different color scheme, but it can only distinguish between any IE browser and the others, not between say Opera and Safari.
If you want to use javascript, look at
http://webdesign.about.com/library/weekly/aa123101a.htm
and
http://webdesign.about.com/library/weekly/aa123101b.htm
(it's a bit ut of date and I haven't tried it. You can use the same method for IE6 and IE7).
Powered by vBulletin® Version 4.2.0 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.