Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Background change when time detected

    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.

  • #2
    New Coder
    Join Date
    Sep 2011
    Location
    England
    Posts
    39
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Is this what you were looking for?

    Place this into the head:
    Code:
    <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>

  • #3
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Not working ... the same background stay still :/

  • #5
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Show your code.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #6
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I just put the code in the head in new html document.
    No full page.

  • #7
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,957
    Thanks
    9
    Thanked 727 Times in 721 Posts
    Code:
    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:

    Code:
    if (timeCheck > 17 || timeCheck < 6)

  • #8
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can you provide full js code ?

  • #9
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,957
    Thanks
    9
    Thanked 727 Times in 721 Posts
    Just replace the "&&" in the code posted above with "||".


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •