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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Want visitors to see different page depending on time of day...

    Hey,

    I was looking for a way to have visitors see two different pages. One page that would display a day time page (during the day). Then at night I want it to automatically redirect to a night time version.

    The time would be based on the local computers clock.

    Any one have any ideas or now of a script?

    Thanks!

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Code:
    <body onload = "switchPage()">
    
    <script type = "text/javascript">
    function switchPage() {
    now = new  Date();
    hh = now.getHours();
    if (hh > 5 && hh < 18) {  // from 0600 to 1759
    window.location = "http://yoursite.com/page1.html";
    }
    else {  // from 1800 to 0559
    window.location = "http://yoursite.com/page2.html";
    }
    }
    </script>
    Obviously you can change the hours to suit.

    The road to happiness is not getting what you want, but wanting what you get. - Philip M

  • #3
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'll give it a go...

    Thank you very much!

  • #4
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,077
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Thumbs up Variation on a theme

    As a variation of the earlier post, you could also redirect hourly:
    PHP Code:
    <body onload "switchPage()">

    <
    script type "text/javascript">
    var 
    sites = [
      
    'http://yoursite.com/page0.html',   'http://yoursite.com/page1.html',
      
    'http://yoursite.com/page2.html',
      
    'http://yoursite.com/page3.html',   'http://yoursite.com/page4.html',
      
    'http://yoursite.com/page5.html',
      
    'http://yoursite.com/page6.html',   'http://yoursite.com/page7.html',
      
    'http://yoursite.com/page8.html',
      
    'http://yoursite.com/page9.html',   'http://yoursite.com/page10.html',
      
    'http://yoursite.com/page11.html',
      
    'http://yoursite.com/page12.html',  'http://yoursite.com/page14.html',
      
    'http://yoursite.com/page14.html',
      
    'http://yoursite.com/page15.html',  'http://yoursite.com/page16.html',
      
    'http://yoursite.com/page17.html',
      
    'http://yoursite.com/page18.html',  'http://yoursite.com/page19.html',
      
    'http://yoursite.com/page20.html',
      
    'http://yoursite.com/page21.html',  'http://yoursite.com/page22.html',
      
    'http://yoursite.com/page23.html'
    ]
      
    function 
    switchPage() {
      var 
    now = new  Date();
      var 
    hh now.getHours();
      
    window.location sites[hh];
    }
    </script> 


  •  

    Posting Permissions

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