在父框架中打开iframe页面(javascript) [英] Open iframe page in parent frame (javascript)

查看:142
本文介绍了在父框架中打开iframe页面(javascript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确信知道的人有解决我面临的这个问题的方法吗?我有一个Index.html网站,其中包含一个Iframe。在这个iframe中,该网站的所有页面都显示... Home.html..Info.html ... Contact.html..etc。

I'm sure someone in the know has a solution to this problem I'm facing? I have a site with Index.html which contains an Iframe. In this iframe, all pages of the site are shown...Home.html..Info.html...Contact.html..etc.

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

I'd like a javascript function so that when you open Home.html via the google sitemap for example, it shows up in the parent frame in Index.html. The function I currently have in the head section of each child page is:

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

虽然这有效,但它不记得子页面并打开索引页面,其中包含默认的iframe页面... Home.html as iframe的编码如下:

Although this works, it doesn't remember the child page and opens the Index page with the default iframe page...Home.html as the iframe is coded like this:

< iframe id =iframesrc =home.htmlallowTransparency =trueid = iframeIDname =iframeIDwidth =100height =100scrolling =noframeborder =no>
< / iframe>

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

Has anybody a solution to this problem, as I've searched everywhere? Thanks.

推荐答案

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

Try to set location.href with a query string, i.e.:

// .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);

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

In index.html create a check for query strings and set the iframe source accordingly:

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

这篇关于在父框架中打开iframe页面(javascript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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