www.webdeveloper.com
Results 1 to 3 of 3

Thread: Refresh Iframes with Javascript not working as desired

  1. #1
    Join Date
    Jan 2012
    Posts
    2

    Refresh Iframes with Javascript not working as desired

    Hello all!

    I'm having a hard time refreshing multiple iframes with the following script below.

    <script type="text/javascript">
    window.setInterval("reloadIFrame();", 5000);
    function reloadIFrame() {
    document.frames["test"].location.reload();
    }
    </script>

    I follow up and do another for each iframe I have.

    <script type="text/javascript">
    window.setInterval("reloadIFrame();", 5000);
    function reloadIFrame() {
    document.frames["tes1"].location.reload();
    }
    </script>


    The unfortunate part is that the test1 will refresh but not the test. The names are correct and everything else appears to be right.


    <div align="left"><iframe name="test" src="stlfp-1.html" height="35" frameborder="0" scrolling="no" width="275"></iframe>
    </div>
    <script type="text/javascript">
    window.setInterval("reloadIFrame();", 5000);
    function reloadIFrame() {
    document.frames["test"].location.reload();
    }
    </script>

  2. #2
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,266
    Do not define the same function (reloadIFrame) twice !
    If you want to reload two (or more) Iframes, insert the commands in an unique function

    Code:
    function reloadIFrame() {
       document.frames["test"].location.reload();
       document.frames["tes1"].location.reload();
    }
    // Call the function all 5000 millisecond 
    window.setInterval(reloadIFrame, 5000);
    Last edited by 007Julien; 01-27-2012 at 09:59 AM.

  3. #3
    Join Date
    Jan 2012
    Posts
    2
    Thanks!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles