views:

403

answers:

4

I have found this code for putting hidden iframe into my html and loading url into it:

var i = document.createElement('iframe');
i.style.display = 'none';
i.onload = function() { i.parentNode.removeChild(i); };
i.src = 'http://www.google.com';
document.body.appendChild(i);

And I would like to ask, can I access in javascript the source code of the google.com loaded in this iframe, please?

+1  A: 

The security features of an iframe will prevent you from accessing the source code inside the iframe using JavaScript. If you want to "screen scrape" you should do two things...

1) Check that it's okay for you to use the data you are scraping.

2) Use a server-side script to load and parse the page.

Sohnee
A: 

The answer hasn't changed in the 45 minutes since you asked the more general version of this question.

David Dorward
I am aware my questions are very similar, maybe the same.. but for beginner like me, it wasn't obvious until now. Thank you and sorry :)
neon
+1  A: 

If the page in the iframe is hosted on the same hostname as the "parent" page, you could access the DOM of the child page from the parent page using JavaScript.

If the childpage is at another hostname, the security features of JS will prevent that.

elzapp
A: 

http://www.dyn-web.com/tutorials/iframes/ - Try this one it helps Joe AWungshi

Joe Awungshi