0

I have created a calculator that I want to iframe on some different sites. The content of the iframe changes when changing the page in the iframe. This makes it so I have a scrollbar in my iframe. Is it possible to set the height of the iframe dynamically according to the content. I have a script that sets the height of the content, but when I add the iframe to that nothing happens.

I've tried some different things including:

On the client side (external website):

jQuery("#myIframe").height(jQuery("#myIframe").contents().find("html").height());

On my side / serverside (where the content for the iframe is hosted):

In my function that sets the height of the content (works perfectly for the content, just not for the actual iframe)

jQuery('#myIframe').height(app_height);

Where app_height is calculated from a bunch of stuff.

I have a feeling maybe it doesn't work because of some cross site thing.

To sum it up, I have a page on my website that contains a calculator. I want that page to be iframed on some different websites externally. The height of the content is set perfectly from my code, but the actual iframe stays the same. Any way to dynamically change the height of the iframe based on the content in it? Either on the external site, or on my site?

Nissen
  • 287
  • 3
  • 17
  • Possible duplicate of [make iframe height dynamic based on content inside- JQUERY/Javascript](https://stackoverflow.com/questions/9162933/make-iframe-height-dynamic-based-on-content-inside-jquery-javascript) – lehmanad1 Jun 13 '19 at 13:16
  • If this is a cross-domain iframe, no. This will not be possible. Theoretically you could send a `postMessage()` to the parent window, but this would require a) the third party domain to listen for the message and b) them to implement the code which resizes the iframe, and as such is very unlikely to work – Rory McCrossan Jun 13 '19 at 13:20
  • Look at this article https://stackoverflow.com/questions/819416/adjust-width-and-height-of-iframe-to-fit-with-content-in-it – Ivijan Stefan Stipić Jun 13 '19 at 13:53
  • Possible duplicate of [Adjust width and height of iframe to fit with content in it](https://stackoverflow.com/questions/819416/adjust-width-and-height-of-iframe-to-fit-with-content-in-it) – Ivijan Stefan Stipić Jun 13 '19 at 13:54

0 Answers0