GetElementById inside iframe

Q: I have an iframe X call page, on page X there is a div w / id=test. The value of this test div is "bubbles". On the parent page, I need to read the div value and save it as javascript var.

Result: there is an output on the parent page document.write(iframedivvalue);that will be = regardless of the value of the div inside the iframe.

Note:

  • page X is currently on a different domain.
  • I am NOT trying to set anything inside an iframe, just read the divs value.
+3
source share
3 answers

You will still be blocked by policies of the same origin if the domains do not match. It doesn't matter if you are just trying to get the value.

+2

, - JavaScript .

iframe , :

document.getElementById('iframe-id').contentDocument.getElementById('canvas');
+3

Assuming iFrame has an assigned id:

var iframe_div = document.getElementById('iframeid').document.getElementById('mydiv');
var content = iframe_div.innerHTML;

I believe that should work.

+2
source

Source: https://habr.com/ru/post/1792650/


All Articles