PDA

View Full Version : Wait in frame



Ahamad
11-07-2008, 11:40 AM
I have made a script which load these files sequencially.in a frame notes1as.txt then notes2as.txt then notes3as.txt then notes4as.txt..................... It loads them

immediately after each other. This is script
<html>
<head>
<script type="text/javascript">

function updateFrame() {
var frame = document.getElementById("loopingFrame");
if(!frame.count)
{
frame.count = 1;
}
{
frame.count++;
}
var a = frame.count;
frame.src = "notes"+a+"as.txt";

}
</script>

</head>
<body>
<iframe id="loopingFrame" src="notes.txt" onload="updateFrame();">
</iframe>
</body>
</html>
I want that there should be 5 sec wait between loading of files. After notes1as.txt, it should wait 5 secs then load notes2as.txt then again wait 5 secs then load

notes3as.txt........ in frame. I have problem using "settimeout" code, where to use it???

jscheuer1
11-07-2008, 03:48 PM
<html>
<head>
<script type="text/javascript">

function updateFrame() {
document.getElementById("loopingFrame").src = "notes" + (updateFrame.count++) + "as.txt";
};
updateFrame.count = 1;
</script>

</head>
<body>
<iframe id="loopingFrame" src="notes.txt" onload="if(updateFrame.count < 4) setTimeout(updateFrame, 5000);">
</iframe>
</body>
</html>

Notes: When hard coded like we have it, the onload event of an iframe may not fire in some browsers, so it is better to add it to the iframe using addEventListener/attachEvent, but the above does illustrate one solution to your question about the timeout.

Ahamad
11-08-2008, 01:19 AM
Thank you very much. Its working.

Ahamad
11-09-2008, 05:41 AM
I want another one.
I want to Redirect after certein time in frame. e.g
There should be a frame. In this frame www.google.com should be loaded 1st then after 10 sec www.yahoo.com then after 10 sec www.msn.com. I have made thing like this


<html>
<head>
<script type="text/javascript">

function updateFrame() {
document.getElementById("loopingFrame");
updateFrame.count = 1;
var a = updateFrame.count;
if (a == 1) {
frame.src = "www.google.com";
};
if (a == 2) {
frame.src = "www.yahoo.com";
};
if (a == 3) {
frame.src = "www.msn.com";
};
};
</script>

</head>
<body>
<iframe id="loopingFrame" src="notes.txt" onload="if(updateFrame.count < 4) setTimeout(updateFrame, 5000);">
</iframe>
</body>
</html>


Whats wrong in it.

jscheuer1
11-09-2008, 06:33 AM
A lot.


Every time the function runs, updateFrame.count is reset to 1.
'frame' is undefined.
The locations given for the the 'frame's src attribute are invalid URL's.


I may of missed something. Try this:


<html>
<head>
<script type="text/javascript">
function updateFrame() {
var f = document.getElementById("loopingFrame");
var a = ++updateFrame.count;
if (a == 1) {
f.src = "http://www.google.com/";
}
if (a == 2) {
f.src = "http://www.yahoo.com/";
}
if (a == 3) {
f.src = "http://www.msn.com/";
}
};
updateFrame.count = 0;
</script>

</head>
<body>
<iframe id="loopingFrame" src="about:blank" onload="if(updateFrame.count < 4) setTimeout(updateFrame, 5000);">
</iframe>
</body>
</html>

Ahamad
11-17-2008, 01:41 AM
I want a difficult thing now.In above frame after 3 websites are loaded, 4th website "www.good.com" should be loaded after 20 secs. There should be another frame in which "www.bad.com" should be loaded after 25 secs. How. ???

Ahamad
11-30-2008, 02:02 PM
Please anyone help

jscheuer1
11-30-2008, 02:44 PM
I didn't answer at first because I didn't think it was all that hard to figure out. But now I was just working on it, and I'm wondering what you even mean. Do you mean that there are two iframes? If so, does the "another frame" load 25 seconds after www.good.com, or 25 seconds after www.msn.com?