应用场景: vue + mui,用hbulider打包后,嵌套其它网页,在网上查HTML页面嵌套 的解决方案,选择使用ifame标签时遇到了height设置无效的问题
1. 通过设置html和body高度,ifame设置height:100%才有效,代码如下:
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
Documenthtml, body {
margin: 0 0;
width: 100%;
height: 100%;
}
iframe {
margin: 0 0;
width: 100%;
height: 100%;
}
function iframeHeight() {
document.getElementById('iframeId').height = "100%";
}
2. ifame 自适应高度, 更为简洁代码如下:
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
Documentvar ifm= document.getElementById("main");
ifm.height=document.documentElement.clientHeight - 28;