應用場景: vue + mui,用hbulider打包后疟呐,嵌套其它網(wǎng)頁拌消,在網(wǎng)上查HTML頁面嵌套 的解決方案,選擇使用ifame標簽時遇到了height設置無效的問題
1. 通過設置html和body高度奈搜,ifame設置height:100%才有效,代碼如下:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="main.js"></script>
<style type="text/css">
html, body {
margin: 0 0;
width: 100%;
height: 100%;
}
iframe {
margin: 0 0;
width: 100%;
height: 100%;
}
</style>
<script type="text/javascript">
function iframeHeight() {
document.getElementById('iframeId').height = "100%";
}
</script>
</head>
<body style="height: 100%">
<div style="text-align:center; height: 100%">
<iframe id="iframeId" frameborder=0 scrolling=auto src=https://m.weibo.cn></iframe>
</div>
</body>
</html>
原文鏈接:iframe height 100% 無效問題解決(轉)
2. ifame 自適應高度盯荤, 更為簡潔代碼如下:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<iframe id="main" name="main" src="https://m.weibo.cn" frameborder="0" width="100%" ></iframe>
</body>
<script>
var ifm= document.getElementById("main");
ifm.height=document.documentElement.clientHeight - 28;
</script>
</html>
原文鏈接:真正的讓iframe自適應高度 兼容多種瀏覽器隨著窗口大小改變
未完待續(xù)...