【问题标题】:How to redirect Iframe to another URL php如何将 iframe 重定向到另一个 URL php
【发布时间】:2011-09-19 04:54:28
【问题描述】:

我有父页面 index.php,在里面我有如下 iframe

<div id="main-content1" style="position:absolute;float:none;top:80px;margin-left:170px;width: 830px;">
            <iframe onload="IfarmeOnload();"  style="display:block; margin-left:none;  margin-right:none; width: 100%; height: 100%;" src="<?php echo $home; ?>" id="rightMenu" name="rightMenu"   frameborder="0"></iframe>

        </div>

当我单击位于父窗口中的链接时,我想根据该 URL 将 iframe 内容重定向到。

然后一旦 iframe 加载成功,我只想重定向整个 index.php 页面一次

编辑

我试过了

echo "<script> document.getElementById('rightMenu').contentWindow.location='http://www.google.lk'</script>";

但这是重定向到 google.lk 以不在 ifamme 中加载

【问题讨论】:

  • iframe 过时了,还有更好的解决方案,例如 ajax
  • 是的,但此刻我别无选择

标签: php javascript jquery iframe


【解决方案1】:

给你的iframe 起个名字:

<iframe name="myIframeName"></iframe>

使用target 属性在所需的超链接中引用您的iframe

<a href="/path/to/page.php" target="myIframeName"></a>

【讨论】:

  • 一旦重定向 iframe 就可以了,我也想刷新我的父窗口而不更改 ifame contnet
  • 重新加载父窗口后,iframe 的状态将不会保留。那时您唯一的选择是在重新加载父窗口后默认 iframe 的源。
  • 另一种选择可能是使用 DOM 操作并完全摆脱 iframe。
  • 有什么办法只刷新父对象而不是ifame
  • 没有。但是,如果您接受我关于 DOM 操作的建议,您将消除与多次往返服务器相关的复杂性和开销,这最终会为最终用户带来分段且不稳定的体验。
【解决方案2】:

我不坐在电脑旁,但我认为 你需要这样的东西 Document.getElementById("rightMenu").location.href

或者试试这个 iframeobj.src = 网址

或与您编写的相同代码但没有内容窗口

【讨论】:

  • 一旦重定向 iframe 就可以了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-12-05
  • 2021-07-22
  • 2014-07-25
  • 2016-01-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多