-
AuthorPosts
-
September 29, 2022 at 1:24 pm #1366886
Hi guys,
can you help me with an issue of iframes?
I want to embed an iframe which should get a dynamic height – depending on the amount of registered people. Therefore I can not set it to x Pixels but need to make the iframe as height as the content is.
It was not working with height=”100%” nor with 100vh.I have that test-page for that issue:
And there is a code block inside with this code:
<iframe src=”https://www.lsc-berlin.de/anmeldung/working_area/anmelden.php?turnier=2″ style=”width: 100%; height:100vh; border: none”></iframe>But as you can see the iframe is ending in the middle and creates a scrollbar. But I want to have that iframe in full height and only one outer scroll-bar from the browser.
Any idea how I can achieve that?
Thank you and best regards,
OliverSeptember 30, 2022 at 7:14 pm #1367144Hey don_olli,
Thanks for the link to your page, in a previous thread I found that the following script would get the height of the iframe page and set the height on load, you will note the iframe code has a function for the height. Try adding this code in your code block element for the script and the iframe link.
This only works if the iframe is the same domain, otherwise you will get a CORs error.<script type="text/javascript"> function calcHeight(iframeElement){ var the_height= iframeElement.contentWindow.document.body.scrollHeight; iframeElement.height= the_height; } </script> <iframe src="https://www.lsc-berlin.de/anmeldung/working_area/anmelden.php?turnier=2" onLoad="calcHeight(this);" frameborder="0" scrolling="no" width="100%" ></iframe>
Below I have linked to my test page of an iframe on my domain.
If this doesn’t help please include an admin login in the Private Content area so we can be of more assistance.Best regards,
MikeSeptember 30, 2022 at 9:12 pm #1367155Hi Mike,
thank you – unfortunatley that code did not work in my case.
The iframed content is on my domain – not on the same sub-domain (“Neueseite.LSC-Berlin.de”) – but same main-domain (“LSC-Berlin.de”). And I also don’t get any errors – but it shows me the iframe in a height of maybe only 100 pixel and then it is cut off. See my Test-IFRAME-PAge from above – which contains now a code-block with your code.
I would be happy if you could assist further.
In private you wil find the Login to the page.
Thanks a lot.
Best regards,
OliverSeptember 30, 2022 at 9:31 pm #1367160Hi,
I see that you are getting a CORs error:(index):294 Uncaught DOMException: Blocked a frame with origin “http://neueseite.lsc-berlin.de” from accessing a cross-origin frame.
at calcHeight (http://neueseite.lsc-berlin.de/test-iframe/:294:50)
at HTMLIFrameElement.onload (http://neueseite.lsc-berlin.de/test-iframe/:298:159)so it looks like your sub-domain is cross-origin blocking, please ask your web host to setup allow cross-origin between your domain and sub-domain, this has to be done on the server.
You can test a page on the same sub-domain and see that this will work, as in my text page.
Typically iframes will only work on the same domain unless the server is set up to allow cross-origin.Best regards,
MikeOctober 1, 2022 at 8:21 am #1367176Hi Mike,
Thanks for checking that…
I will anyway bring both sites on one domain in a few weeks after the development-phase – therefore I will not go the way to my provider now to allow COR.
So then I would suggest you can close this for now – and I will check your script in a few weeks when both sites are running under same domain.
So thank you very much for your hint.
Have a great weekend,
OliverOctober 1, 2022 at 12:33 pm #1367189Hi,
Thanks for the update, I’ll close this thread for now then. Please open a new thread if you should have any further questions or problems.
Best regards,
Rikard -
AuthorPosts
- The topic ‘Dynamic height of iFrame to 100%’ is closed to new replies.