首页 > 代码库 > 确实可行的iframe
确实可行的iframe
今天又一次研究了iframe自适应高度,下面的代码确实可行。
<html>
<head>
<script type="text/javascript">
function SetCwinHeight()
{
var ifm = document.getElementById("dd");
var subWeb = document.frames ? document.frames["dd"].document : ifm.contentDocument;
if (ifm != null && subWeb != null)
{
ifm.height = subWeb.body.scrollHeight;
}
}
</script>
</head>
<body>
<button type="button" onclick="document.getElementById(‘dd‘).src=http://www.mamicode.com/‘b.html‘;">
A</button>
<button type="button" onclick="document.getElementById(‘dd‘).src=http://www.mamicode.com/‘c.html‘;">
B</button>
<iframe id="dd" src="http://www.mamicode.com/b.html" onl oad="SetCwinHeight();" frameborder="0" width="100%" scrolling="no" marginheight="0" marginwidth="0" />
</body>
</html>