您好,我想根据屏幕大小设置 iframe 的 css 高度,但我不知道该怎么做。
CSS:
#iframeplate{
width:100%;
height:200px;
}
HTML:
<body onload="setGround()">
<iframe id="iframeplate" class="idIframe" frameborder=0 border=0 width="100%" scrolling-y="no" src="#">
</iframe>
</body>
JS:
<script type="text/javascript">
function setGround() {
var groundElement = document.getElementById('iframeplate');
groundElement.style.height = getWindowHeight() + 'px';
}
}
</script>
谁能看出为什么这行不通?或者关于更好的方法的任何想法?
最佳答案
错误是getWindowHeight
方法没有输出。
试试这个:
groundElement.style.height = window.screen.availHeight + 'px';
关于javascript - 使用javascript设置iframe的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12363046/