views:

332

answers:

2

Hi,

I have a window, with an iframe in it. When i clicking a button, then the iframe will load (loaded from a web site). Is it possible to retrieve the content of that iframe? How can I retrieve the content of that page?

I can view the source code by left clicking iframes View Source.

I need to store the source in a DB.

1. var iframe = document.getElementById("ifrm");

alert(iframe.contentWindow.document.body.innerHTML );

2.alert(window.frames['ifrm'].document.body.innerHTML);

these two comments are showing "access denied" error.

Please help me.

+2  A: 

This should work (if it's on the same domain):

document.getElementById('iframeId').contentWindow.document.body.innerHTML

Note that you need to make sure the frame has been loaded completely before you run this code. Otherwise, you will get strange exceptions.

Disclaimer: I have not tested this.

Here's the google query I used: google query

Ryan Emerle
document.frames['frame-name'] should work, too.
Aaron Digulla
+1  A: 

It is generally not possible to read the contents of an iframe loaded from another server, due to the same origin security policy. However, it looks like you want to store the content on the server anyway, so why not request the content from the server?

phihag
what do you actually mean?
praveenjayapal
You are right, I wrote mostly gibberish. Tried to clear it up. Better now?
phihag