View Full Version : Calling CSS with a function?
bdmovies1
06-20-2006, 03:43 AM
Does anybody know how this would work? I can't figure out how to call the css
function resize()
{
if (screen.width >=640) {
img.banner.src=banner640.jpg;
document.write(<LINK HREF="style640.css" REL=Text/CSS>);
}
else if (screen.width >=800) {
img.banner.src=banner800.jpg;
document.write(<LINK HREF="style800.css" REL=Text/CSS>);
}
else if (screen.width <= 1040) {
img.banner.src=banner.jpg;
document.write(<LINK HREF="style.css" REL=Text/CSS>);
}
shachi
06-20-2006, 03:51 PM
Did you forget to place quotes around the text or did you do that by purpose??
Try this:
function resize(){
if (screen.width >=640) {
img.banner.src = "banner640.jpg";
document.write("<link rel='stylesheet' type='text/css' href='style640.css' />");
} else if (screen.width >=800) {
img.banner.src = "banner800.jpg";
document.write("<link rel='stylesheet' type='text/css' href='style800.css' />");
} else if (screen.width <= 1040) {
img.banner.src = "banner.jpg";
document.write("<link rel='stylesheet' type='text/css' href='style.css' />");
}
And by the way please don't forget to place [\CODE][/CODE] tags around your codes.
You shouldn't be doing this. The banner resizing is understandable, but using a different stylesheet based on screen resolution is a very bad idea. Using Javascript to choose that stylesheet is an even worse one. Redesign your site, and do it properly this time.
shachi: Don't convert code to XHTML from HTML. See http://www.hixie.ch/advocacy/xhtml for reasons not to use XHTML -- quite aside from the fact that if the OP is using HTML, s/he is probably using an HTML doctype.
shachi
06-20-2006, 04:32 PM
Thanks Twey for the link, going through it.:)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.