View Full Version : Background change when time detected

01-21-2012, 12:30 AM

Im not sure this thread is in the right forum because im new, so if the location is false then change it.

I need a code that will change the background of site when the time comes.
For example:

When the time come to 17:59 then the background changes and sit still to 05:59, at 6 oclock the background changes and sit still to 17:59.

If this is possible, please provide the code.


Dom Mv
01-21-2012, 01:20 AM
Is this what you were looking for?

Place this into the head:

<script type="text/javascript">
var obtainTime = new Date();
var timeCheck = obtainTime.getHours();
if (timeCheck > 17 && timeCheck < 6){
document.body.style.background = '#000000'; // Black / Night
document.body.style.background = '#FFF000'; // Yellow / Day

01-21-2012, 01:51 AM
so I need to change #FFF000 code with my path to the background, right ?
Im so new to jquery and javascript, but one day I will learn :D

01-21-2012, 12:15 PM
Not working ... the same background stay still :/

01-21-2012, 12:21 PM
Show your code.

01-22-2012, 11:13 AM
I just put the code in the head in new html document.
No full page.

01-22-2012, 11:34 AM
if (timeCheck > 17 && timeCheck < 6)

is never going to be true - timeCheck will never be greater than 17 AND less than 6. It should be an OR:

if (timeCheck > 17 || timeCheck < 6)

01-22-2012, 02:00 PM
Can you provide full js code ?

01-22-2012, 02:37 PM
Just replace the "&&" in the code posted above with "||".

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum