article

Sunday, May 13, 2012

Auto iframe’s height using javascript

Auto iframe’s height using javascript
<script type="text/javascript">

function iFrameHeight() { 
var f = document.getElementById('blockrandom'); 
f.style.height = '100px' ; 
var d = (f.contentWindow.document || f.contentDocument) ;

var height = Math.max(d.documentElement.scrollHeight, d.body.scrollHeight) ;

height += 20; 
f.style.height = height + 'px' ; 
f.setAttribute("height", height) ;

}
</script>

<iframe onload="iFrameHeight()" id="blockrandom"
 name=""
 src="test.htm" 
 width="100%"
 height="200"
 scrolling="no"
 align="top"
 frameborder="0"
 class="wrapper">
 No Iframes</iframe>

Related Post