1
<script>
function getDef() {
    document.getElementById("defCanvas").innerHTML=document.getElementById("invisibleDefFrame").contentWindow.document.getElementsByClassName("def-content")[0].innerText;
}
</script>
<button onclick="getDef();">Get Definition</button>
<iframe style="display:none;" id="invisibleDefFrame" src="http://dictionary.reference.com/browse/amalgamation?s=t"></iframe>
<p id="defCanvas"></p>

This is my code for a program that should return the definition of a word, but instead does nothing. What should I do to fix it? Thanks.

Zooza S
  • 137
  • 3
  • 13

2 Answers2

1

Because of cross-domain security, I suspect that you are not able to access the HTML of that iframe from within your own page via Javascript.

See this previous answer.

I believe that the only way to do what you are trying to do - scrape results from another website and display them on your own - is to make the request via your own web server, parse the results and present it to the user.

Community
  • 1
  • 1
stef
  • 13,499
  • 2
  • 42
  • 66
0

You can't access the iframe this way!

You will get an Uncaught SecurityError: Blocked a frame with origin

Read this detailed answer

Community
  • 1
  • 1
Moïze
  • 662
  • 7
  • 15