开发者

What is the correct way to get innerHTML of iframe

After googling a lot I have tried various ways to get innnerHTML of开发者_运维问答 an iframe but none is working at least in Chrome 7.0 and neither in Firefox 3.6

Basically I am implementing a file uploader using iframe within a form and with the target of the form set to the iframe so that the response from server gets added to the iframe. Then I registered an eventHandler for "load" event which is where I want to check the response for which I require the innerHTML of the iframe.

Following are the various ways I have tried to get the document of the iframe window from within the onload eventHandler but it is always undefined

  1. window.frames[0].contentWindow.document
  2. window.frames[0].document
  3. window.frames[0].contentDocument
  4. document.getElementById('iframe_id').contentWindow.document

I am using the 0 index as there is only one iframe in the main window Also the response from the server does gets displayed inside the iframe and the event handler is also getting called

Can someone please help as to what is the right way to get innerHTML of iframe which works in most browsers like FireFox 3.0+ and IE6.0+ and Chrome


Perhaps this is overkill, but I would use a div and call the jQuery function load on it. It's not exactly an iframe, but it should work all the same as well as allow you to call $('div').html() and get the exact contents of the page as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜