Results 1 to 5 of 5

Thread: iFrame Content change twice a day w/ text as content

  1. #1
    Join Date
    Jun 2014
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default iFrame Content change twice a day w/ text as content

    Hello! I have found this code (http://www.dynamicdrive.com/dynamici...dowiframe2.htm) for an iFrame content changer that switches everyday of the month, but I need the program to change content twice a day for the entire month. The change should happen 12 hours apart. The time the change occurs is not important. Could you help me with this? Thank you!

    As a note: This is a small portion of a larger project: creating a small, artificial stock market website that will be used as a demonstration tool for students. The ultimate goal is to have fake stock tickers update twice a day, displaying fake stock prices and referring to the stock's previous price. This is meant to be an interim step towards that goal.
    Last edited by NVBeef; 06-09-2014 at 06:27 AM.

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    your link is broken but

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    </head>
    
    <body>
    <iframe id="iframe" frameborder="1" ></iframe>
    
    
    <script type="text/javascript">
    /*<![CDATA[*/
    
    function zxcIFrameSwapper(o){
     var id=o.IFrameID,a=o.URLs,i=document.getElementById(id);
     if (i&&a instanceof Array){
      var n=new Date(),s=new Date(n.getFullYear(),n.getMonth(),1),src=a[(Math.floor((n-s)/1000/60/60/24)*2+(n.getHours()>=12?1:0))%a.length];
      if (i.src!=src){
       i.src=src;
      }
      o.to=setTimeout(function(){ zxcIFrameSwapper(o) },60000);
     }
    }
    
    zxcIFrameSwapper({
     IFrameID:'iframe',
     URLs:[ // as many URLs as required for days in month*2
      'http://www.dynamicdrive.com/forums/forumdisplay.php?7-JavaScript',
      'http://www.dynamicdrive.com/forums/forumdisplay.php?23-Looking-for-such-a-script-or-service',
      'http://www.dynamicdrive.com/forums/forumdisplay.php?2-Dynamic-Drive-scripts-help'
     ]
    });
    /*]]>*/
    </script>
    </body>
    
    </html>
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  3. The Following User Says Thank You to vwphillips For This Useful Post:

    NVBeef (06-10-2014)

  4. #3
    Join Date
    Jun 2014
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Thank you very much Vic! That will work beautifully. Now, I have a comprehension question if you do not mind. What particularly within that script governs the time changes? It seems like it would be the block headed by: function zxcIFRameSwapper. I was going to see if I could use that same mechanic to control the times in which this program runs: function getRandomInt(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
    That way I could have the single webpage run the algorithm to generate stock prices every half-day.
    This would be my ultimate goal, but thank you for all your help!

  5. #4
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    Code:
    Math.floor((n-s)/1000/60/60/24)// the number of days between the 1st of the month and the current date
    Code:
    Math.floor((n-s)/1000/60/60/24)*2// the number of half days
    Code:
    +(n.getHours()>=12?1:0)// plus 0 before 12 or 1 after 12
    I am not sure of what Math.floor(Math.random() * (max - min + 1)) + min; achieves and when function getRandomInt is called
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  6. The Following User Says Thank You to vwphillips For This Useful Post:

    NVBeef (06-10-2014)

  7. #5
    Join Date
    Jun 2014
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Thank you! I think that has solved all the issues! As a note, the math.random code was a non uniform, range-restricted generator.

Similar Threads

  1. Tab Content Script: Change content selector to class
    By konstikonst in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 02-05-2011, 08:50 PM
  2. change bg color of a scrollable content text
    By janalyssa in forum JavaScript
    Replies: 3
    Last Post: 04-25-2008, 04:55 AM
  3. Switch Content: Change Text Size of Header
    By ro1960 in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 08-02-2007, 05:00 PM
  4. Replies: 5
    Last Post: 07-17-2005, 05:27 PM
  5. Replies: 0
    Last Post: 06-03-2005, 07:00 AM

Bookmarks

Posting Permissions

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