为何在iframe里面的按钮要点击两次,iframe才会自动调整到指向的文件的高度
网页a.htm有个iframe ,这个iframe指向了b.htm ,现在b.htm有个按钮,点击按钮以后b.htm的总体页面高度会增大或缩小,但不知道怎样可以令a.htm的iframe高度也随着增大或缩小。
现在的代码如下,iframe的高度可以增大或缩小,但需要点击两次在b.htm中的按钮才会实现,我想知道如何才能点击一次就增大或缩小?
a.htm的代码
<!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" />
<style type="text/css">
<!--
body,td,th {
color: #FFFFFF;
}
body {
background-color: #B91A1A;
}
.STYLE1 {
color: #4AA5C8;
font-weight: bold;
}
-->
</style>
</head>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="30" align="center"><iframe src="b.htm" name="sample" width="614" marginwidth="0" marginheight="0" scrolling="No" frameborder="0" id="sample" onload="this.height=this.contentWindow.document.body.scrollHeight;"></iframe></td>
</tr>
</table>
</body>
</html>
b.htm的代码
<!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>
<style type="text/css">
<!--
body,td,th {
color: #FFFFFF;
}
body {
background-color: #990000;
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
<script type="text/javascript" language="javascript">
function GetPhoto(photourl)
{
document.getElementById("image").src=photourl;
parent.window.document.all.sample.height=document.body.scrollHeight;
}
</script>
</head>
<body>
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="top"><img src="a.jpg" name="image" id="image" /></td>
</tr>
<tr>
<td height="30"> </td>
</tr>
</table>
<table width="600" border="0" cellspacing="1" cellpadding="0">
<tr>
<td align="left" valign="top"><br>
<a href="#"><img src="a_s.jpg" width="60" height="60" border="0" onClick="GetPhoto('a.jpg')" /></a><a href="#"><img src="b_s.jpg" width="60" height="60" border="0" onClick="GetPhoto('b.jpg')" /></a></td>
</tr>
</table>
<table width="600" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="left" valign="top">| 重点案例 | 品牌形象 |</td>
</tr>
</table>
</body>
</html>
a.jpg是一个600*360像素的图片,b.jpg是一个240*400的图片,a_s.jpg和b_s.jpg分别是它们的缩略图