dropfaith Posted September 28, 2008 Share Posted September 28, 2008 i Know the code below works to change style sheets based on the hour of the day but is there a possible solution to also make it change styles based on the month dynamically.. i want the site to change styles 4 times a year following the seasons and all i have found so far is by the hour <SCRIPT LANGUAGE="JavaScript"> <!-- Begin function getCSS() { datetoday = new Date(); timenow=datetoday.getTime(); datetoday.setTime(timenow); thehour = datetoday.getHours(); if (thehour > 20) display = "tree_twilight.css"; else if (thehour > 17) display = "tree_sunset.css"; else if (thehour > 14) display = "tree_afternoon.css"; else if (thehour > 11) display = "tree_noon.css"; else if (thehour > 7) display = "tree_morning.css"; else if (thehour > 4) display = "tree_sunrise.css"; else if (thehour > 1) display = "tree_twilight.css"; else display = "tree_sunset.css"; var css = '<'; css+='link rel="stylesheet" href=' + display + ' \/'; css+='>'; document.write(css); // End --> } </script> <script language="javascript">getCSS();</script> <noscript> <link rel="stylesheet" href="tree_sunset.css" type="text/css"> </noscript> Quote Link to comment Share on other sites More sharing options...
CroNiX Posted September 28, 2008 Share Posted September 28, 2008 You don't need javascript to do that. in the head: <?php $seasoncss=""; switch(date("n")){ case 3: $seasoncss="spring.css"; break; case 6: $seasoncss="summer.css"; break; case 9: $seasoncss="fall.css"; break; case 12: $seasoncss="winter.css"; break; } echo "<link rel=\"stylesheet\" href=\"$seasoncss\" type=\"text/css\">"; should be close and will work with javascript turned off. Quote Link to comment Share on other sites More sharing options...
dropfaith Posted September 28, 2008 Author Share Posted September 28, 2008 im trying to avoid it working on server time or day seasons on the other side of wolrd are different Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 28, 2008 Share Posted September 28, 2008 change your datetoday.getHours() to datetoday.getMonth. Remember, though, the getMonth function returns months in 0-11, not 1-12. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.