Make iframe automatically adjust height according to the contents without using scrollbar?
Add this to your <head>
section:
<script>
function resizeIframe(obj) {
obj.style.height = obj.contentWindow.document.documentElement.scrollHeight + 'px';
}
</script>
And change your iframe to this:
<iframe src="..." frameborder="0" scrolling="no" onload="resizeIframe(this)" />
As found on sitepoint discussion.
set the iframe height automatically
Try this coding
<div>
<iframe id='iframe2' src="Mypage.aspx" frameborder="0" style="overflow: hidden; height: 100%;
width: 100%; position: absolute;"></iframe>
</div>
Adjust width and height of iframe to fit with content in it
<script type="application/javascript">
function resizeIFrameToFitContent( iFrame ) {
iFrame.width = iFrame.contentWindow.document.body.scrollWidth;
iFrame.height = iFrame.contentWindow.document.body.scrollHeight;
}
window.addEventListener('DOMContentLoaded', function(e) {
var iFrame = document.getElementById( 'iFrame1' );
resizeIFrameToFitContent( iFrame );
// or, to resize all iframes:
var iframes = document.querySelectorAll("iframe");
for( var i = 0; i < iframes.length; i++) {
resizeIFrameToFitContent( iframes[i] );
}
} );
</script>
<iframe src="usagelogs/default.aspx" id="iFrame1"></iframe>
Can't find a way to automatically resize my iframe to fit its content
Creating the ifame element dynamically solved this problem.
See: Creating an IFRAME using JavaScript
And: Make iframe automatically adjust height according to the contents without using scrollbar?
Also the lang attribute seemed to be the culprit in the first place.
It’s also not very clear as to why the iframe does not respond as intended with the HTML lang attribute. Perhaps that’s only the case on this project?
Here you can find info on the iframe https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe and its attributes.
And here you have info on Global HTML attributes...https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes.
Related Topics
Submit Form Without Page Reloading
How to Call PHP Functions by JavaScript
How to Bypass Access-Control-Allow-Origin
Execute PHP Function With Onclick
Why Are Inline Event Handler Attributes a Bad Idea in Modern Semantic Html
Why Is Using Onclick() in HTML a Bad Practice
Why Don't Self-Closing Script Elements Work
Strip HTML from Text JavaScript
How to Check Whether a Checkbox Is Checked in Jquery
Offsetting an HTML Anchor to Adjust For Fixed Header
Why Does My Http://Localhost Cors Origin Not Work
How to Get the Data-Id Attribute
How to Programmatically Tell an HTML Select to Drop Down (For Example, Due to Mouseover)
In What Situations Would Ajax Long/Short Polling Be Preferred Over Html5 Websockets