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 7 of 7
  1. #1
    New Coder
    Join Date
    May 2006
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Days in the week - JavaScript

    Hello,
    I have a marquee in my site and and I have 7 corresponding html pages for 7 days of the week. I would like to have a day detection so (e.g) saturday.html will go in my iframe on my hompage, please make it idiot proof because im a rookie

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Please try the following

    PHP Code:
    <HTML>
    <
    HEAD>
    <
    TITLE>Document Title</TITLE>
    <
    script type="text/javascript">

    currentDate=new Date()
    currentDay=currentDate.getDay()

    function 
    loadIframe(){

    switch(
    currentDay){

    case 
    0:
    loc="saturday.html "
    break

    case 
    1:
    loc="monday.html "
    break

    case 
    2:
    loc="tuesday.html "
    break

    case 
    3:
    loc="wednsaday.html "
    break

    case 
    4:
    loc="thursday.html "
    break

    case 
    5:
    loc="friday.html "
    break

    case 
    6:
    loc="saturday.html "
    break

    default:
    alert("Oops")
    }

    parent.frames['iframe_name'].location=loc

    }
    </script>
    </HEAD>
    <BODY onload="loadIframe()">

    <iframe name="iframe_name" src=""></iframe>

    </BODY>
    </HTML> 
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #3
    New Coder
    Join Date
    May 2006
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts
    still having some problems, it does not load
    can i change it to a table instead? and can i have it just so it redirects it

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Thinking that the days of the week starts from 0 (Sun) in CPU, to speed the loading you may rename your pages:

    0.html //sunday
    1.html//monday
    ... and so on

    and simply use

    <script type="text/javascript">
    var today=new Date();
    var d=today.getDay();
    onload= function(){
    top.frames['frame_or_iframe_name'].location.href=d+'.html'
    }
    </script>
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    New Coder
    Join Date
    May 2006
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok lol got a code from another site, just gotanother quick question

    <script language="javascript">

    var today = new Date();
    thisday = today.getDay();
    var time = today.getHours();

    if ((thisday == 1 && time >= 6) || (thisday==2 && time < 6)){
    document.location="monday.html"
    }

    what does the this day and time mean?
    cheers

  • #6
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #7
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    That script is changing the image at 6am each morning (based on the time set on your visitor's computer).
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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