Iframes resizing to dynamic content
Iframes resizing to dynamic content
I am trying to make my iframe resize itself to the content i put inside it. My problem is that it works as long as the content is longer but as soon as the content is shorter it does not become smaller. I have tried multiple solutions which don't work.
Is it possible to refresh only the iframe component and not the whole page every x milliseconds? That might solve my problem.
Edit 3*
<head>
function resizeIframe(objIframe) {
objIframe = document.getElementById('myiframe');
objIframe.style.height = 'auto';
objIframe.style.height = obj.contentDocument.documentElement.offsetHeight + 'px';
}
</head>
<body>
http://./home.php
</body>
obj
document
obj.contentDocument.documentElement.offsetHeight
Edited above. Sorry i am a newbie at this. I was trying to read previous related posts but none of them seem to work
– Seigfried
2 days ago
The problem is that the
html
element (what documentElement refers to) has the same height as the viewport. So if you made your iframe have 500px height once already, reading back the offsetHeight of documentElement will always return you a value of 500, even if the actual content has shrunk to less by now. Try with the height of the body element instead.– CBroe
2 days ago
html
objIframe.body.scrollHeight + 'px' didnt work
– Seigfried
2 days ago
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
No, your edit is worse than the first rev (
obj
is undefined anddocument
is the one your main page). And what you want isobj.contentDocument.documentElement.offsetHeight
.– Kaiido
2 days ago