从单独的 iframe 中的.php刷新 iframe

refresh iframe from a .php in a separate iframe

本文关键字:iframe php 刷新 中的 单独      更新时间:2023-09-26

我有一个由 7 种不同的 iframe 构建的页面:

<iframe id="leftframe" src="structure/leftbar.php"></iframe>
<iframe id="headerframe" src="structure/header.php"></iframe>
<iframe id="menuframe" src="structure/menu.php"></iframe>
<iframe id="timerframe" src="structure/times.php"></iframe>
<iframe id="settingsframe"></iframe>
<iframe id="contentframe" name="contentframe"></iframe>
<iframe id="chatframe" src="chat/index.php"></iframe>

我有一个在"内容框架"中运行的.php。当我单击其中的按钮时,它会向.php发送post.php运行正常,但在结束时,我希望它重新加载leftframe帧。

我尝试了这些页面上的建议:

如何使用Javascript刷新IFrame?使用 JavaScript 重新加载/刷新 iframe 的最佳方法是什么?

但这些似乎都不起作用。

在我正在尝试.php

?>
    <script>
        parent.getElementById('leftframe').location.reload();
        alert("Ping");
    </script>
<?php

这也行不通。有什么建议吗?

谢谢!

当可以在客户端刷新 iframe 时,使用后端刷新 iframe 是绝对错误的。

它对我有用:

<script>
     document.getElementById('leftFrame').contentWindow.location.reload(); 
     alert('Ping');
</script>

而且,是的,您确定需要 iframe 吗?
这绝对不是一个好的做法。特别是在一个强大的JS及其框架和AJAX的世纪中。如果您更新 DOM 元素的内容而不是刷新 iframe 会更好。