-1

How to retrieve html code from an iframe ?

I try:

$('#iframe').innerHtml
$('#iframe').contents()

Its not works.

Have you a idea ?

Thanks

  • 2
    Possible duplicate of [get iframe content as string](https://stackoverflow.com/questions/30116410/get-iframe-content-as-string) – mwil.me Jun 27 '17 at 00:59

1 Answers1

4

Due to Cross-Origin Resource Sharing (CORS) you can only access the content if the iframe is on the same domain.

The following javascript will work if it's the same domain:

document.getElementById('iframe').contentWindow.document.body.innerHTML 
Matt
  • 718
  • 6
  • 20