javascript - 如何将哈希值从页面传递到 URL 到 iframe?

标签 javascript html iframe

我有一个类似这样的页面:

http://mypage.com/about#peter

在该页面的 html 中我有一个 iframe:

<iframe src="doit" />

我希望 #peter 转到 iframe。也就是说,我希望 iframe 渲染为

<iframe src="doit#peter />

关于如何实现这一点有什么建议吗?

谢谢

最佳答案

您可以在页面运行时以编程方式创建 iframe,并将哈希标签附加到它。

var hash = window.location.hash;
var ifrm = document.createElement("IFRAME"); 
ifrm.setAttribute("src", "http://mypage.com/about" + hash); 
document.body.appendChild(ifrm);

关于javascript - 如何将哈希值从页面传递到 URL 到 iframe?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15589500/

相关文章:

javascript - 谷歌地图 API v3。功能 showMarkers() 只是隐藏/清除新标记

php - 通过 POST 将值提交到多个 PHP 文件

javascript - 无法捕获 Web 套接字异常

JavaScript - DOM 操作 - 单击提交按钮后尝试创建 <li> 元素

jquery - 如何创建从 CSS 下拉菜单到幻灯片 2 上的 iframe 的链接

JavaScript/JQuery : multidimensional array loosing scope when initialized in nested loop

javascript - 如何根据链接点击显示相同的DIV容器和不同的内容

html - Nav brand 和 nav pills 不在同一条线上

google-chrome - 为什么在--disable-web-security并删除x-frame-options header 后仍然显示此错误?

javascript - 选择所有 iframe 并使用 javascript 检查它们