src 跳转中的 Iframe 锚点链接
Iframe anchor link in src jumping
我在页面中间有一个iframe。我正在尝试在 iframe 中显示另一个页面,但要向下开始几段,而不是在顶部。
所以我在我的 iframe src 中放置了一个锚点,对应于我另一个页面中的锚点名称标签。
iframe 本身滚动正常,但页面的主体也会滚动,以便 iframe 的顶部位于屏幕顶部,这不是我的意图。
有没有办法只滚动iframe,主页的顶部仍然在屏幕顶部?
<iframe scrolling="no" src="http://www.mysite.com/#anchorlink"></iframe>
您可以临时将主页的正文样式位置设置为"固定",然后在 iframe "onload" 事件中将其重置为默认值,例如为您的 iframe 提供一个 ID
<iframe scrolling="no" id = "ifr"></iframe>
并添加以下代码:
var ifr = document.getElementById("ifr");
document.body.style.position = "fixed";
ifr.onload = function() {document.body.style.position = ""};
ifr.src = "http://www.mysite.com/#anchorlink"
将 iframe 放在表标记中,并为 iframe 提供所需的高度,这样如果不需要,它也可以避免滚动
<table>
<tr>
<td>top section</td>
</tr>
<tr>
<td><iframe frameborder="0" height='650px;' width='100%'
id="pageframe" name="pageframe" src="http://www.mysite.com/#anchorlink"> </iframe>
</td>
</tr>
<tr>
<td>bottom section</td>
</tr>
</table>
相关文章:
- 如何使用angularjs在iframe中嵌入来自数据库的视频链接
- 使用Javascript将链接转换为iframe
- 如何防止iframe中的链接在新选项卡中打开
- iframe resizer内部的锚点链接不'不起作用
- 创建使用 ajax 更新 iframe 的链接
- 警报后转到 iframe 中的图像链接
- 取消 iframe 中具有 target=“_parent” 属性的链接事件
- 如何从iframe中删除链接
- 同一域链接正在顶部iFrame中加载,而不是在整个页面上加载
- 用Javascript正则表达式替换iframe到可点击的YouTube链接
- 删除所有<link>iframe中的元素
- 防止iframe破坏会杀死网站上的所有链接
- 按日期为iframe创建一个HTML链接
- iOS Phonegap网页链接嵌入iframe开放系统浏览器,而不是iframe
- Iframe.如何将链接加载到iframe中
- Js从外部域在父级的iframe中打开链接
- 如何告诉 iframe 将图像链接调整为给定的宽度和高度
- 单击链接时播放iframe视频
- 如何在谷歌网站中显示与iframe中的特定人员共享的谷歌云端硬盘html链接
- 在父母的iframe中打开链接/更具体的“_parent”