Skip to content

Switch CSS according to the hours of the day

  • by
  1. <SCRIPT LANGUAGE=“JavaScript”>
  2. <!– Begin
  3. function getCSS()
  4. {
  5. datetoday = new Date();
  6. timenow=datetoday.getTime();
  7. datetoday.setTime(timenow);
  8. thehour = datetoday.getHours();
  9. if (thehour > 20)
  10. display = “tree_twilight.css”;
  11. else if (thehour > 17)
  12. display = “tree_sunset.css”;
  13. else if (thehour > 14)
  14. display = “tree_afternoon.css”;
  15. else if (thehour > 11)
  16. display = “tree_noon.css”;
  17. else if (thehour > 7)
  18. display = “tree_morning.css”;
  19. else if (thehour > 4)
  20. display = “tree_sunrise.css”;
  21. else if (thehour > 1)
  22. display = “tree_twilight.css”;
  23. else
  24. display = “tree_sunset.css”;
  25. var css = ‘<‘;ย  css+=‘link rel=”stylesheet” href=’ + display + \/;ย  css+=‘>’;
  26. document.write(css);
  27. // End –>
  28. }
  29. </script>
  30. <script language=“javascript”>getCSS();</script>

Note

The author of this code does not tell where put it in the file… i suppose the good place is between <head> tags. You just have to build your cssheets as you want and you’re done! ๐Ÿ˜€