js控制iframe自适应高实例

2015年03月27日 javascript 暂无评论 阅读 33 views 次

iframe1.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<script type="text/javascript" language="javascript">
function iFrameHeight() {
var ifm= document.getElementById("iframepage");
var subWeb = document.frames ? document.frames["iframepage"].document : ifm.contentDocument;
if(ifm != null && subWeb != null) {
ifm.height = subWeb.body.scrollHeight;
}
}
</script>
<body>
aaaaaaaaaaaaaaa
<iframe onLoad="iFrameHeight()" src="http://localhost/iframe2.html" id="iframepage"  frameBorder="1" scrolling="no" width="100%" >
</iframe>
bbbbbbbbbbbbbb
</body>
</html>

1-140PG0063R48
iframe2.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body style="padding:0; margin:0;">
1111111111
<div style="border:#00FFFF thin solid; width:300px; height:300px; background:#CCCC99"></div>
2222222222
</body>
</html>

给我留言

您必须 登录 才能发表留言!

Copyright © 大一网 保留所有权利.  

用户登录

分享到: