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

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

问题描述

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

解决方案

过去一天我一直在努力。这似乎是你如何访问iframe。如果你使用 document.getElementById(),你会得到一个Iframe对象,它没有 onload 事件。但是,如果您通过 window.frames [] 数组访问,例如

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

你得到一个窗口对象,它确实有onload事件。



(即使用frame id属性,但ff使用name属性。 / p>

然后,您可以将

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

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


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

解决方案

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'],

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

(ie uses the frame id attribute , but ff uses name attribute. So use both and make the same)

You can then assign

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

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

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

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