在父页面显示iframe div内容
我确信这是非常基本的,但我似乎无法找到任何适合我的解决方案。基本上,我需要从 iframe 获取 div 的内容,并将它们写入父页面中的 div 中。这就是我所拥有的:
<iframe src="slideshows/slideshow/case2.html" frameborder=0 scrolling="no"
id="frame1" name="frame1"></iframe>
<div id="caption">
<script type="text/javascript">
var caption = frame1.document.getElementById('slidecaption');
document.write(caption);
</script>
</div>
“slidecaption”是我试图抓取的 iframe 中 Id 的名称。
我得到的只是“空”。是因为 iframe 内容还没有加载吗?如果是这样,我如何延迟直到 iframe 加载完毕?
谢谢, 斯科特
感谢你们俩的帮助。我根据 Márcio 的想法弄清楚了:
我将函数放在父页面中:
<script type="text/javascript">
function send() {
document.getElementById('slidecaption').innerHTML =
frame1.document.getElementById('slidecaption').innerHTML}
</script>
并将调用放在 iframe 文档中:
<body onload="parent.send();">
问候, 斯科特
I'm sure this is pretty basic, but I can't seem to get any of the solutions I've found to work for me. Basically, I need to get the contents of a div from an iframe, and write them to a div in the parent page. This is what I have:
<iframe src="slideshows/slideshow/case2.html" frameborder=0 scrolling="no"
id="frame1" name="frame1"></iframe>
<div id="caption">
<script type="text/javascript">
var caption = frame1.document.getElementById('slidecaption');
document.write(caption);
</script>
</div>
'slidecaption' is the name of Id in the iframe that I'm trying to grab.
All I get is "null". Is it because the iframe contents haven't loaded yet? If so, how do I delay until the iframe has loaded?
Thanks,
Scott
Thanks to both of you for your help. I figured it out, based on Márcio's idea:
I put the function in the parent page:
<script type="text/javascript">
function send() {
document.getElementById('slidecaption').innerHTML =
frame1.document.getElementById('slidecaption').innerHTML}
</script>
And I put the call in the iframe document:
<body onload="parent.send();">
Regards,
Scott
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定这是您唯一需要做的事情,但您肯定需要从 dom 检索frame1。
I'm not sure this is the only thing you need to do, but you certainly need to retrieve frame1 from the dom.