通过 js
来控制 iframe
的高度,监听浏览器被重置大小时的 onresize
事件,对 iframe
的高度重新赋值。
引入 jquery.min.js
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<iframe src="https://blog.csdn.net/NengHong" id="myiframe" scrolling="auto" frameborder="0" width="100%"></iframe>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script>
$(document).ready(function(){
//高度设置
var height = $(window).height();
$('#myiframe').height(height);
})
function changeFrameHeight(){
var ifm= document.getElementById("myiframe");
$('#myiframe').height($(window).height());
}
window.onresize=function(){
changeFrameHeight();
}
</script>
</body>
</html>