Skip to content Skip to sidebar Skip to footer

Auto Refresh IFrame HTML

How do I auto Refresh a Iframe every 3 Seconds with out it refreshing the entire page. I use but it shows the entire page refresh and

Solution 1:

You have problems with your html tags. (the "iframe" tag is malformed)

Here you have your code fixed and your answer ready to run:

<!DOCTYPE html>
<html>
<head>
    <link rel="shortcut icon" href="favicon.png" type="image/x-icon" />
    <title>Chat</title>
    <style>
        body {
            margin: 0px;
        }
        h1 {
            font-family: arial;
            font-size: 100%;
        }
        iframe {
            width: 900px;
            height: 500px;
        }
        div.top {
            background-color: rgba(2, 109, 8, 0.83);
            height: 30px;
            width: 100%;
        }
    </style>
</head>
<body>
    <div class="top">
        <img src="favicon.png" alt="favicon" height="31" width="31">
        <h1>Chat</h1>
    </div>

    <iframe id="iframe" src="text.txt"></iframe>

    <script>
        window.setInterval(function() {
            reloadIFrame()
        }, 3000);

        function reloadIFrame() {
            console.log('reloading..');
            document.getElementById('iframe').contentWindow.location.reload();
        }
    </script>
</body>
</html>

Regards


Solution 2:

<head>
    <script>
        function refreshIFrame() {
            var x = document.getElementById("*Your_iframe_id*");
            x.contentWindow.location.reload();
            var t = setTimeout(refreshIFrame, 3000);
        }
    </script>
</head>
<body onload="refreshIFrame()">... 
    <iframe id="*Your_iframe_id*" src= ...></iframe>...
</body>

this solution worked for me, I discovered that the 'refreshIFrame()' function was entered as a parameter without the braces () in the following line: " var t = setTimeout(refreshIFrame, 3000); ". Just substitute the relevant values and you are good to go.


Solution 3:

You could accomplish what you need by simply using a few lines of Javascript.

 <script>
 window.setInterval("reloadIFrame();", 3000);

 function reloadIFrame() {
  document.frames["frameNameHere"].location.reload();
 }
 </script> 

Post a Comment for "Auto Refresh IFrame HTML"