在 iframe 加载中读取 iframe 内容 [英] Reading Iframe Content in Iframe Load

查看:52
本文介绍了在 iframe 加载中读取 iframe 内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想学习如何在 iframe 的 onLoad 事件中读取 iframe 内容并将其内容写入主页?谢谢..

I just wanna learn how to read Iframe content in onLoad event of iframe and write it's content to the main page ? Thanks..

推荐答案

过去一天我也遇到了同样的问题.您如何访问 iframe 似乎很重要.如果你使用 document.getElementById() 你会得到一个 Iframe 对象,它没有 onload 事件.但是,如果您通过window.frames[] 数组访问,例如

I have struggled with same this past day. It seems to matter how you access the iframe. If you use document.getElementById() you get an Iframe object, which has no onload event. However, if you access through window.frames[] array, for example

var iframeWindow = top.frames['iframeID'],

你得到一个 window 对象,它确实有 onload 事件.

you get a window object, which does have onload event.

(即使用 frame id 属性,但 ff 使用 name 属性.所以两者都使用并使其相同)

然后您可以分配

iframeWindow.onload=function(){iframeContent=iframeWindow.document.body.innerHTML;};

请注意,由于 iframeWindow 是一个窗口对象,因此您可以使用窗口语法来访问内容.

Notice, since iframeWindow is a window object, you use window syntax to access content.

这篇关于在 iframe 加载中读取 iframe 内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆