Forum Moderators: open

Message Too Old, No Replies

Javascript/CSS help

Site falls back on wrong CSS sheet

         

vurrt

5:33 pm on Aug 2, 2009 (gmt 0)

10+ Year Member



Hey all,

I needed help and this seemed like a helpful forum so here I am..

So here's the problem:

if(screen.width<1280) {
document.write('<link title="smallresfirefox" href="smallresfirefox.css" rel="stylesheet" type="text/css" />')
document.write('<!--[if IE]><link rel="stylesheet" type="text/css" href="smallresie.css" media="screen" /><![endif]-->');
}
else
document.write('<link title="firefox" href="firefox.css" rel="stylesheet" type="text/css" />')
document.write('<!--[if IE]><link rel="stylesheet" type="text/css" href="ie.css" media="screen" /><![endif]-->');

As you can see im trying to make it work so that a different CSS sheet is loaded @ different resolutions and with firefox and ie..
It works perfectly well except for 1 thing, namely when I open the page in IE in small resolution it somehow uses the 'ie.css' file instead of the 'smallresie.css' file, but when i remove the ie.css file from the folder it succesfully uses the smallresie.css file.. Why is this? And how can I fix this?

I posted this in Javascript because I'm guessing it's a javascript error, and I'm not good at JS

vurrt

5:43 pm on Aug 2, 2009 (gmt 0)

10+ Year Member



Never mind - fixed it

I just moved the ie.css to a different folder and directed the script there, I don't know why it didn't work in the first place but oh well

vurrt

6:00 pm on Aug 2, 2009 (gmt 0)

10+ Year Member



Wait... I didn't :/

help!

eelixduppy

6:13 pm on Aug 2, 2009 (gmt 0)



You need to surround the else block with braces...

else
{
document.write('<link title="firefox" href="firefox.css" rel="stylesheet" type="text/css" />')
document.write('<!--[if IE]><link rel="stylesheet" type="text/css" href="ie.css" media="screen" /><![endif]-->');
}

See if that fixes the problem.

And welcome to WebmasterWorld! :)

vurrt

6:42 pm on Aug 2, 2009 (gmt 0)

10+ Year Member



it worked :D

thanks man!