Posted By

lucian on 10/04/10


Tagged


Versions (?)

Who likes this?

8 people have marked this snippet as a favorite

bobbym245
Shujin
triptych
abdulaziz
Saharabbey
wazdesign
guo3823538
Beppoi


Change CSS based on time of the day


 / Published in: JavaScript
 

Use this in the <head> of your HTML files.

  1. <link rel="stylesheet" type="text/css" media="screen, projection" href="screen.css" />
  2. <script type="text/javascript">
  3. <!--
  4. var d = new Date();
  5. var sunrise = 6; // 6 AM
  6. var sunset = 18; // 6 PM
  7. var currentHour = parseInt(d.getHours());
  8. if(currentHour >= sunset || currentHour <= sunrise){
  9. document.write('<link rel="stylesheet" href="dark.css" media="screen, projection" /' + '>');
  10. }
  11. // -->
  12. </script>

Report this snippet  

You need to login to post a comment.