0

I have a fancybox showing an iframe with some content from another domain.

I want to determine it's content's height when it's loaded. If I use

document.body.scrollHeight 

(in the iframe content document's javascript), it gives me the right height in case there is a vertical scrollbar or the screen becomes higher. However if the iframe becomes smaller, that just gives me the previous height. I thought to solve this by using

document.body.height

then but that returns undefined. Is there another way to get the body's height (since the iframe content's body actually has the right height if I inspect it through the browser's developer tools? Or might it have something to do with the fact that the function is called in $(window).load?

Thanks

Mats Raemen
  • 1,781
  • 1
  • 28
  • 41
  • Due to the [Same-origin Policy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Same_origin_policy_for_JavaScript) you can't retrieve properties on a third party page. If you can control the page within `iframe`, you can find some alternatives from this [SO answer](http://stackoverflow.com/a/3076648/1169519). – Teemu Nov 09 '13 at 20:34
  • possible duplicate of [set fancybox height with jquery](http://stackoverflow.com/questions/19876787/set-fancybox-height-with-jquery) – JFK Nov 09 '13 at 21:47
  • I pass it to the domain showing the fancybox through postMessage, so it can. I just need a way to determine the body's height inside the iframe so I can pass that. – Mats Raemen Nov 09 '13 at 21:47
  • JFK I beg to differ. That question is about setting a fancybox height manually when you know which height it's supposed to be. This one is about getting an iframe actual content height within the frame itself (as it turned out I didn't always send the right height through). It seemed best to split the questions as one doesn't necessarily have anything to do with the other. – Mats Raemen Nov 09 '13 at 21:58

0 Answers0