iframe height 100% 无效问题

应用场景: vue + mui,用hbulider打包后,嵌套其它网页,在网上查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自适应高度 兼容多种浏览器随着窗口大小改变
未完待续...

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容