Refresh an iframe

后端 未结 4 1606
终归单人心
终归单人心 2021-01-05 17:38

How to refresh an iframe? For example:


I click on \"Videos\" in this iframe ,then c

相关标签:
4条回答
  • 2021-01-05 17:48

    You can't refresh the inner document in there due to the single origin policy.

    Have you tried changing the iframe's src property and adding a random GET string to force a reload?

    This should work:

    <iframe id="myiframe" src="http://google.com"></iframe>
    
    document.getElementById("myiframe").src = "http://www.google.com?"+(+new Date());
    
    0 讨论(0)
  • 2021-01-05 17:50

    My solution was to remove previous iframe and append new iframe with new src.

    0 讨论(0)
  • 2021-01-05 17:52

    I think just by updating the hre/src will work. So on button click do as follows:

    window.frames.iframeName.location.href = "new url"

    0 讨论(0)
  • 2021-01-05 18:00

    You can only reload the current iframe href if it's for the same domain (single origin policy) with following code:

    <iframe id="myIframe" src="http://yourdomain.com"></iframe>
    
    document.getElementById('myIframe').contentWindow.location.reload(true);
    

    or get the current href

    var currentHref = document.getElementById('myIframe').contentWindow.location.href;
    
    0 讨论(0)
提交回复
热议问题