Autoresize iframe to it's height

This script autoresizes an iframe from within it's body. This is useful when you don't have access to the parent.

by humancoder 1 year, 5 months ago and tagged with: html iframe javascript
1
2
3
4
5
6
7
8
9
/**
* <body onload="autoResize('myIframe')">
**/
function autoResize(iframe_id){
	try{//Auto resize if iframe
		var frame = top.document.getElementById(iframe_id);
		frame.height = frame.contentDocument.body.scrollHeight;
	}catch(e){}//An error is raised if the IFrame domain != its container's domain
}

Currently 0 comments

To post a comment, you must login.