问题描述
我在页面上有两个iframe,其中一个对另一个进行更改,但另一个iframe在我刷新之前不显示更改。
I have two iframes on a page and one makes changes to the other but the other iframe doesn't show the change until I refresh. Is there an easy way to refresh this iframe with jQuery?
<div class="project">
<iframe id="currentElement" class="myframe" name="myframe" src="http://somesite.com/something/new"></iframe>
</div>
推荐答案
如果iframe不在不同的域中,可以做这样的事情:
If the iframe was not on a different domain, you could do something like this:
document.getElementById(FrameID).contentDocument.location.reload(true);
但由于iframe位于不同的域中,因此您将被拒绝访问iframe的 contentDocument
属性的。
But since the iframe is on a different domain, you will be denied access to the iframe's contentDocument
property by the same-origin policy.
但是如果你的代码运行在iframe的父页面上,通过设置它的src属性为自己,你可能会强迫跨域iframe重新加载。像这样:
But you can hackishly force the cross-domain iframe to reload if your code is running on the iframe's parent page, by setting it's src attribute to itself. Like this:
// hackishly force iframe to reload
var iframe = document.getElementById(FrameId);
iframe.src = iframe.src;
如果您尝试从另一个iframe重新加载iframe,那么您运气不好,那是不是可能。
If you are trying to reload the iframe from another iframe, you are out of luck, that is not possible.
这篇关于用jQuery重新加载iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!