简体   繁体   中英

Refresh an iframe

How to refresh an iframe? For example:

<iframe src="http://google.com"></iframe>

I click on "Videos" in this iframe ,then click on a button to refresh the iframe and I want when the iframe is refreshed ,to be on that "Videos" page.

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());

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;

我的解决方案是删除以前的iframe并使用新的src追加新的iframe。

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM