...

View Full Version : Background change when time detected



daretomk
01-21-2012, 01:30 AM
Hello.

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.

Regards,
daretomk.

Dom Mv
01-21-2012, 02: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();
document.write(timeCheck);
if (timeCheck > 17 && timeCheck < 6){
document.body.style.background = '#000000'; // Black / Night
}else{
document.body.style.background = '#FFF000'; // Yellow / Day
}
</script>

daretomk
01-21-2012, 02: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

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

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

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

SB65
01-22-2012, 12:34 PM
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)

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

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum