首页 > 解决方案 > 每 5 分钟重复一次自动刷新 IFrame

问题描述

我有一个 iframe,我需要每五分钟刷新一次。我有以下内容,但它只会刷新准时。我需要它每五分钟刷新一次。

        <table class="auto-style7">
        <tr>
            <td class="auto-style4">
                </td>
        </tr>
        <tr>
            <td class="auto-style2">
                <p class="auto-style13" style="text-align: center; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; text-indent: 0px; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">
                    Map does not auto-refresh.&nbsp; To update map you will need to manual refresh the page. (Click on warnings to get full details)</p>
                <iframe width="1850" src="website url" class="auto-style8" height="650">
                     <script type="text/javascript">
    function refreshiframe() 
    { 
        parent.frame1.location.href ="website url" 
        setTimeout("refreshiframe()",3000); 
    } 
                     </script>

<body  onload="refreshiframe();">
                </iframe>
                <br />
                </td>
        </tr>
    </table>
&nbsp;
        <br />```

标签: iframepage-refresh

解决方案


我找到了解决方案。通过在 iframe 之前放置正确的脚本并给 iframe 一个 id:

        <script>
            function reload() {
                document.getElementById("ifr").src = "website url"
            }

            setInterval(reload, 60000)
        </script>
        <table class="auto-style7">
        <tr>
            <td class="auto-style4">
                </td>
        </tr>
        <tr>
            <td class="auto-style2">
                <p class="auto-style13" style="text-align: center; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; text-indent: 0px; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">
                    Map auto-refreshes every 5 minutes.&nbsp; Warnings update every minute (Click on warnings to get full details).</p>
                <iframe width="1850" src="website url" class="auto-style8" height="650" id="ifr"></iframe>
                <br />
                </td>
        </tr>
    </table>
&nbsp;
        <br />```

推荐阅读