在Iframe加载中读取Iframe内容 [英] Reading Iframe Content in Iframe Load
问题描述
我只想学习如何阅读iframe的onLoad事件中的Iframe内容并将其内容写入主页面?谢谢..
过去一天我一直在努力。这似乎是你如何访问iframe。如果你使用 document.getElementById()
,你会得到一个Iframe对象,它没有 onload
事件。但是,如果您通过 window.frames []
数组访问,例如
var iframeWindow = top.frames ['iframeID'],
你得到一个窗口对象,它确实有onload事件。
(即使用frame id属性,但ff使用name属性。 / p> 然后,您可以将 请注意,由于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 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 Notice, since iframeWindow is a window object, you use window syntax to access content. 这篇关于在Iframe加载中读取Iframe内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
iframeWindow.onload = function(){ iframeContent = iframeWindow.document.body.innerHTML;};
document.getElementById()
you get an Iframe object, which has no onload
event. However, if you access through window.frames[]
array, for examplevar iframeWindow = top.frames['iframeID'],
iframeWindow.onload=function(){iframeContent=iframeWindow.document.body.innerHTML;};