Wednesday, September 15, 2010

Resizing iframe

Recently I been trying to resize the iframe inside the body so that there would be always one scroll bar on the body. Following few lines of js resolved such problem.

...

<head>

<script type="text/javascript">

function resizeFrame(frame){

var fSize = frame.contentWindow.document.body.scrollHeight;

frame.style.height = fSize + 'px';

}

</script>

</head>

<body>

...

<iframe height="100%"  width="100%" src="url_for_page_to_load" onload="resizeFrame(this)" />

...

</body>

..

now, as soon as frame is loaded, its height is resized so removes the extra scroll bar. I tested this on chrome and ff, works well. Don't know about IE

Cheers!

No comments: