使用 jQuery 重新加载 iframe [英] Reload an iframe with jQuery

查看:55
本文介绍了使用 jQuery 重新加载 iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个页面上有两个 iframe,一个对另一个进行了更改,但另一个 iframe 在我刷新之前不会显示更改.有没有一种简单的方法可以用 jQuery 刷新这个 iframe?

<iframe id="currentElement" class="myframe" name="myframe" src="http://somesite.com/something/new"></iframe>

解决方案

如果 iframe 不在不同的域中,您可以执行以下操作:

document.getElementById(FrameID).contentDocument.location.reload(true);

但由于 iframe 位于不同的域中,同源策略.

但是,如果您的代码在 iframe 的父页面上运行,您可以通过将其 src 属性设置为自身来强制重新加载跨域 iframe.像这样:

//hackishly 强制 iframe 重新加载var iframe = document.getElementById(FrameId);iframe.src = iframe.src;

如果您尝试从另一个 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>

解决方案

If the iframe was not on a different domain, you could do something like this:

document.getElementById(FrameID).contentDocument.location.reload(true);

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.

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;

If you are trying to reload the iframe from another iframe, you are out of luck, that is not possible.

这篇关于使用 jQuery 重新加载 iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆