Skip to content

Instantly share code, notes, and snippets.

@fwon
Last active April 8, 2016 04:51
Show Gist options
  • Save fwon/e43915ed9dd4e8cb13324d67fb5c5e5a to your computer and use it in GitHub Desktop.
Save fwon/e43915ed9dd4e8cb13324d67fb5c5e5a to your computer and use it in GitHub Desktop.
父页有多个iframes时,各iframe自适应高度
<!--a.html-->
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p>parent</p>
<iframe src="b.html" onload="resizeIframe(this)"></iframe>
<p></p>
<iframe src="c.html" onload="resizeIframe(this)"></iframe>
<script type="text/javascript">
function resizeIframe(iframe) {
iframe.height = iframe.contentWindow.document.body.clientHeight + "px";
//iframe.height = iframe.contentWindow.document.body.scrollHeight + "px";
}
</script>
</body>
</html>
<!--b.html-->
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<style type="text/css">
*{
padding: 0;
margin: 0;
}
</style>
<body>
<div>
<p>child-1</p>
<p>child-1</p>
<p>child-1</p>
<p>child-1</p>
<p>child-1</p>
<p>child-1</p>
<p>child-1</p>
<p>child-1</p>
</div>
</body>
</html>
<!--c.html-->
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<style type="text/css">
* {
padding: 0;
margin: 0;
}
</style>
<body>
<div>
<p>child-2</p>
<p>child-2</p>
<p>child-2</p>
<p>child-2</p>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment