Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getElementById within iframe

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

Outcome: on the parent page have a document.write(iframedivvalue); output that will = whatever the value of the div inside the iframe.

Note:

  • as of right now page X is on a different domain.
  • I am NOT trying to set anything inside the iframe, just read a divs value.
like image 475
webmaster alex l Avatar asked Oct 20 '25 07:10

webmaster alex l


2 Answers

As Alex says on the comment above, you will still be blocked by the JavaScript 'same-origin' policy.

If your iframe is on the same domain, then you could try this:

document.getElementById('iframe-id').contentDocument.getElementById('canvas');
like image 115
Meetai.com Avatar answered Oct 21 '25 20:10

Meetai.com


You will still be blocked by the same-origin policy if the domains mismatch. Doesn't matter if you're just trying to grab a value.

like image 42
Alex Avatar answered Oct 21 '25 20:10

Alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!