我有一个类似这样的页面:
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/