PDA

View Full Version : iFrame Content change twice a day w/ text as content



NVBeef
06-09-2014, 05:12 AM
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.

vwphillips
06-09-2014, 12:45 PM
your link is broken but


<!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>

NVBeef
06-09-2014, 10:48 PM
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!

vwphillips
06-10-2014, 09:41 AM
Math.floor((n-s)/1000/60/60/24)// the number of days between the 1st of the month and the current date






Math.floor((n-s)/1000/60/60/24)*2// the number of half days




+(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

NVBeef
06-10-2014, 03:21 PM
Thank you! I think that has solved all the issues! As a note, the math.random code was a non uniform, range-restricted generator.