0

The following iframe is embedded on https://third-party-site.com:

<iframe src="https://example.com/widget" />

https://example.com/widget is rendering dynamic content and I'd like to set iframe's height according to content's height to avoid having a scrollbar.

How could I get the iframe element from the widget page where the content is rendered?

window.frameElement unfortunately returns null because the domains are different:

If the window isn't embedded into another document, or if the document into which it's embedded has a different origin, the value is null instead.

Trying to access the iframe inside iframe's onload results in:

Uncaught DOMException: Blocked a frame with origin "https://third-party-site.com" from accessing a cross-origin frame.

Misha Moroshko
  • 157,453
  • 220
  • 487
  • 722
  • It may not be the best method, but there are [ways to circumvent the same-origin policy](https://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy) – async await Dec 04 '21 at 05:21

0 Answers0