让 <iframe> 跳转的页面在整个窗口(父框架)中打开

问题描述

因为网页头部header(包含导航栏和搜索框) 在很多网页都重复,所以单独写为一个header.html 文件,然后在需要出现的各页面用<iframe> 引入。header.html 里包含搜索框,搜索并经服务器跳转返回后只在当前限定了大小的<iframe> 区域打开,而不是整个页面。

解决误区

看到别的教程是能通过获取刷新后页面的地址然后传递给父页面再在父页面打开

下面是获取指定Id的<iframe> 里的地址的代码,然而经过尝试获取不到,不知道原因何在,遂问题没有解决

<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="javascript" cid="n8" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">var iframeSrc=window.parent.document.getElementById("theIframeId").contentWindow.location.href ;`</pre>

正确解决办法

在提交搜索参数的 <form> 表单里使用target 属性,即在 <form> 标签里添加 target="_parent"

target 的其它属性值如下:

7346071-1e347671785347f7
image

参考链接

[1] form表单的target属性

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值