Javascript 如何将散列从页面传递到iframe的URL?

Javascript 如何将散列从页面传递到iframe的URL?,javascript,html,iframe,Javascript,Html,Iframe,我有一个类似这样的页面: http://mypage.com/about#peter 在该页面的html中,我有一个iframe: <iframe src="doit" /> 我想让彼得去看电影。也就是说,我希望iframe渲染为 <iframe src="doit#peter /> 您可以在页面运行时以编程方式创建iframe,并向其附加哈希标记 var hash = window.location.hash; var ifrm = document.crea

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

http://mypage.com/about#peter
在该页面的html中,我有一个iframe:

<iframe src="doit" />

我想让彼得去看电影。也就是说,我希望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);

我尝试了最上面的一行,希望html能够足够聪明地将哈希标记传递给iframe。