Results 1 to 8 of 8

Thread: Wait in frame

  1. #1
    Join Date
    Oct 2008
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Wait in frame

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

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    <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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Oct 2008
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you very much. Its working.

  4. #4
    Join Date
    Oct 2008
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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
    Code:
    <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.

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

    Code:
    <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>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Oct 2008
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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. ???

  7. #7
    Join Date
    Oct 2008
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Please anyone help

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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
  •