Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing CSS Doesnt work

Status
Not open for further replies.

Ghost81st

Programmer
Nov 8, 2004
5
US
I dont understand what I am doing wrong, anyone willing to pitch their two cents?

<html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 //EN" "<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<link href="index1280.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
<!--
function RedirectCSS(){
if ((screen.width == 1024))
link = document.getElementsByTagName( "link" )[ 0 ];
link.href = "index1024.css";
else if ((screen.width == 1152))
link = document.getElementsByTagName( "link" )[ 0 ];
link.href = "index1152.css";
else if ((screen.width == 800))
link = document.getElementsByTagName( "link" )[ 0 ];
link.href = "index800.css";
else
link = document.getElementsByTagName( "link" )[ 0 ];
link.href = "index1280.css";
//-->
</script>
<head>
<title>HubbellLandscapes.com/Home</title>
</head>
<body>
 
First suggestion:

Code:
function RedirectCSS(){
    var h;
    switch(screen.width) {
        case '1024':
            h = "index1024.css";
            break;
        case '1152':
            h = "index1152.css";
            break;
        case '800':
            h = "index800.css";
            break;
        default:
            h = "index1280.css";
            break;
    }
    document.getElementsByTagName("link")[0].href = h;
}

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
cLFlaVA,
what you gave me doesnt work. It does exactly what it did when I had the other code. Ideas?
 
Maybe add an id to your stylesheet and use document.getElementById("stylesheet")?

Also, try posting in Forum216.

--Chessbot

"See the TURTLE of enormous girth!"
-- Stephen King, The Dark Tower series
 
what do u mean Id for my SS? I am fairly new, so I am not sure what you mean byt that...
 
Code:
<link href="index1280.css" rel="stylesheet" type="text/css" [red]name="sizestyles" id="sizestyles"[/red]>
Code:
function RedirectCSS(){
    var h;
    switch(screen.width) {
        case '1024':
            h = "index1024.css";
            break;
        case '1152':
            h = "index1152.css";
            break;
        case '800':
            h = "index800.css";
            break;
        default:
            h = "index1280.css";
            break;
    }
    document.[red]getElementById("sizestyles")[/red].href = h;
}

--Chessbot

"See the TURTLE of enormous girth!"
-- Stephen King, The Dark Tower series
 
Do I have to do something Special other than making the CSS sheets, and inputing that code? I did it like so:
Code:
<html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 //EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<head>
<link href="index1280.css" rel="stylesheet" type="text/css" name="sizestyles" id="sizestyles">
<script type="text/javascript">
function RedirectCSS(){
    var h;
    switch(screen.width) {
        case '1024':
            h = "index1024.css";
            break;
        case '1152':
            h = "index1152.css";
            break;
        case '800':
            h = "index800.css";
            break;
        default:
            h = "index1280.css";
            break;
    }
    document.getElementById("sizestyles").href = h;
}
</script>
<title>HubbellLandscapes.com/Home</title>
</head>
<body>
 
This seems to be more of a Javascript than a HTML problem. Here's a few points you should consider:

1. Do you get any javascript errors? Check when page is rendered.
2. Are you getting the values you expected? Try alert(screen.width) to see if the values are what you are catching with your code.
3. Do you have the .css files ready where they are supposed to be and are different enough for you to see the difference.
4. Try to tell us more about WHAT is not working.
 
Your problem is that you never call RedirectCSS. Use this as your body tag:
Code:
<body [red]onload="RedirectCSS();"[/red]>

Add anything else you have into it.

--Chessbot

"See the TURTLE of enormous girth!"
-- Stephen King, The Dark Tower series
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top