0

I am trying to get the height of a iframe hosted on a different HTTPS domain, with the following code:

var iframeHeight = document.querySelectorAll("iframe-widget__window").clientHeight;

iframeHeight.height = iframeHeight.contentWindow.document.body.scrollHeight + "px";

However I get the following error: Uncaught TypeError: Cannot read property 'contentWindow' of undefined

I have tried to check other questions on stackoverflow and many people are talking about wrapping the functionality in an load function, but that does not seem to work either. Even if I let the page finish loading completely and use the code in the console I still get the error.

Could it perhaps be Same-origin policy issues?

Mikkel Fennefoss
  • 857
  • 1
  • 9
  • 32
  • You can't access it due to same origin policy. Also `querySelectorAll()` returns a collection, not a single element and selector used is invalid – charlietfl Jan 21 '19 at 13:53
  • In the past I’ve used the following library across domains https://davidjbradshaw.github.io/iframe-resizer/ – odlp Jan 21 '19 at 13:56

0 Answers0