how to refresh an iframe automatically

拟墨画扇 提交于 2019-12-28 15:21:28

问题


I would like an iframe to refresh itself to the source path specified. What is the easiest way to do this inline with javascript?

thanks,


回答1:


If you're also perhaps looking for a way of doing this without javascript enabled, and have access to modify the iframe HTML, then you could add this reload code to the <head> tag of the iframe HTML:

<meta http-equiv="refresh" content="600">



回答2:


You can use setInterval(function, milliseconds, param1, param2, ...)

Something like this:

var frameRefreshInterval = setInterval(function() {
    document.getElementById("myframe").src = document.getElementById("myframe").src
}, 2000);

The interval resets the iframe's src attribute ever 2 seconds (2000 milliseconds)

Edit, to answer you comments: This, along with any other code that manipulates the DOM, should be in a window.onload event listener or similar like so:

<script type=text/javascript>
window.onload = function() {
    var frameRefreshInterval = setInterval(function() {
        document.getElementById("myframe").src = document.getElementById("myframe").src
    }, 2000);
    // any other code
}
</script>



回答3:


setInterval(function(){
    document.getElementById("myframe").src+="";
},2500);



回答4:


Try this

function refresh()
{
    var iframe = document.getElementById('iframe');
    iframe.reload(true);
}

setTimeout('refresh()', 3000);

Note, this will try to refresh the page every 3 seconds. Obviously, if the page takes a while to load, i.e. over 3 seconds then you wont see anything.

Hope this helps.




回答5:


Try This

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

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


Interval Time Is 3 Second.




回答6:


If you want to refresh an iframe itself.

document.getElementById('iframe');//this may not work

and you can try this.

window.frameElement.src = window.frameElement.src


来源:https://stackoverflow.com/questions/6975765/how-to-refresh-an-iframe-automatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!