0

I'm loading an iframe with jquery and I would like to scrape content from the iFrame.
The content is on a diffrent domain than my own.

For some reason I keep getting the alert as "undefined".

<iframe id="myiframe" src="http://www.cnn.com" style="width:1000px; height:300px;"></iframe>

<script>
    setTimeout(function() {
        alert($("#myiframe").children("div").html());
    },5500);
</script>
Nir Tzezana
  • 2,275
  • 3
  • 33
  • 56

2 Answers2

3

You can't do anything with iframe content if content belongs to other domain.

This is short but full answer for this question

Manish Kumar
  • 10,214
  • 25
  • 77
  • 147
  • Ok, but how is this possible, the content is in my document and I just want to travel inside it. What's blocking me? JS? – Nir Tzezana Jun 08 '14 at 08:51
  • Its called `cross domain` restriction. Yes it is in ur page but iframe is diffrent from div or other html element whose content yu can access. For security reason iframe doesnt allow access of other domain content – Manish Kumar Jun 08 '14 at 08:54
0

There is no way around it but to use a proxy - but I would question whether there would be legal issues in doing so.

Read here https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

andyw_
  • 490
  • 5
  • 15