Loading a different background color depending upon the time.

vishalneeraj-24503
Posted by vishalneeraj-24503 under JavaScript category on | Points: 40 | Views : 261
<script type="text/javascript">
var now = new Date();
var hours = now.getHours();

document.write('<style type="text/css">')

//18-19 night
if (hours > 17 && hours < 20)
{
document.write('body{background:pink; color:#FFFFFF;} a{color: yellow !important}')
}

//20-21 night
if (hours > 19 && hours < 22)
{
document.write('body{background:orangered; color:#FFFFFF;} a{color: yellow !important}')
}

//22-4 night
if (hours > 21 || hours < 5)
{
document.write('body{background:black; color:#FFFFFF;} a{color: yellow !important}')
}

//9-17 day
if (hours > 8 && hours < 18)
{
document.write('body{background:deepskyblue; color:#FFFFFF;} a{color: yellow !important}')
}

//7-8 day
if (hours > 6 && hours < 9)
{
document.write('body{background:skyblue; color:#FFFFFF;} a{color: yellow !important}')
}

//5-6 day
if (hours > 4 && hours < 7)
{
document.write('body{background:steelblue; color:#FFFFFF;} a{color: yellow !important}')
}

document.write('<\/style>')

</script>

Comments or Responses

Login to post response