HTML DOM IFrame width attribute
Definition and Usage
width property sets or returns iframe element width attribute values.
width attribute specifies the width of the iframe.
grammar
iframeObject.width=value
width attribute can have the following values:
值 | 描述 |
---|---|
pixels | 以像素作为单位 (如"100px" 或者 "100") |
% | 以百分比作为宽度 (如 "20%") |
Browser Support
All major browsers support width attribute
Examples
Examples
Change iframe height and width:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function changeSize(){
document.getElementById("myframe").height="300";
document.getElementById("myframe").width="300";
}
</script>
</head>
<body>
<iframe id="myframe" src="http://www.w3big.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>本教程(w3big.com)</title>
<script>
function changeSize(){
document.getElementById("myframe").height="300";
document.getElementById("myframe").width="300";
}
</script>
</head>
<body>
<iframe id="myframe" src="http://www.w3big.com" height="200" width="200">
<p>你的浏览器不支持iframes。</p>
</iframe>
<br><br>
<input type="button" onclick="changeSize()" value="修改大小">
</body>
</html>
try it"
Frame / IFrame objects