在父框架(javascript)中打开iframe页面

Open iframe page in parent frame (javascript)

本文关键字:iframe 页面 框架 javascript      更新时间:2023-09-26

我确定知情人士有解决我面临的这个问题的方法吗?我有一个带有索引的网站.html其中包含一个 Iframe。在此iframe中,将显示网站的所有页面...首页.html..信息.html...联系方式.html..等。

我想要一个javascript函数,以便当您通过google站点地图打开Home.html时,它会显示在Index.html的父框架中。我目前在每个子页面的 head 部分中具有的功能是:

<script> if (parent.location.href == self.location.href){ window.location.href = 'index.html' } </script>

虽然这有效,但它不会记住子页面并使用默认 iframe 页面打开索引页面......主页.html因为 iframe 是这样编码的:

<iframe id="iframe" src="home.html" allowTransparency="true" id="iframeID" name="iframeID" width="100" height="100" scrolling="no" frameborder="no"> </iframe>

有没有人解决这个问题,因为我到处搜索过?谢谢。

尝试使用查询字符串设置location.href,即:

// .getAttribute so we don't get the absolute URL
var src = document.getElementById("iframe").getAttribute("src");
if (parent.location.href === self.location.href)
    location.href = "index.html?" + escape(src);

在索引中.html创建查询字符串检查并相应地设置 iframe 源:

if (location.search)
    document.getElementById("iframe").src =
            unescape(location.search.substring(1));