点击即可更新iFrame的iFrame页面/内容

时间:2013-02-13 19:49:53

标签: php javascript jquery iframe refresh

如果你已经阅读了我之前的一些问题,你知道我遇到了一个问题,我用iFrame解决了这个问题。无论如何,我现在想要的是当我点击更新按钮时能够更新iFrame显示的页面(它是我的本地页面)。如果不更新我正在使用的页面,这怎么可能?

背景资料: 我在home.php,我有一个iFrame。这个iFrame显示页面something.php,这是我的一个页面。我必须能够更新home.php而无需等待something.php更新,因此解决方案是将它们放在两个文档中然后使用iFrames包含它(现在home.php可以显示而无需等待something.php) 。这个something.php的内容是动态的,并根据其他网页进行更新。假设用户想要更新此iFrame的内容,或者内容未显示。然后他将获得一个“更新”按钮,它只会刷新something.php页面,而无需刷新home.php

可以这样做(最好是在PHP中,但也欢迎使用JavaScript / jQuery)?

2 个答案:

答案 0 :(得分:1)

您必须使用客户端脚本执行此操作。

有些事情:

<input type="button" onclick="reLoadIframe();">

reLoadIframe(){
  document.getElementById('iframeYoureTryingToUpdate').contentWindow.location.reload();
}

reLoadIframe(){
  document.getElementById('iframeYoureTryingToUpdate').src =document.getElementById('iframeYoureTryingToUpdate').src`
}

答案 1 :(得分:0)

只需在loc中提供网址,这应该足够了。

var loc = "http://example.com/example.php";
var frameId = "myFrame";
document.getElementById(frameId).src = loc;
相关问题