• iframe高度自适应,自适应子页面高度


    html

    <iframe id="mainFrame" name="mainFrame" scrolling="no" src="Index.html"
                frameborder="0" style="padding: 0px;  100%; height: 1000px;"></iframe>

    js调用

    <script type="text/javascript">
            startInit('mainFrame', 560);
    </script>

    js

    var browserVersion = window.navigator.userAgent.toUpperCase();
    var isOpera = browserVersion.indexOf("OPERA") > -1 ? true : false;
    var isFireFox = browserVersion.indexOf("FIREFOX") > -1 ? true : false;
    var isChrome = browserVersion.indexOf("CHROME") > -1 ? true : false;
    var isSafari = browserVersion.indexOf("SAFARI") > -1 ? true : false;
    var isIE = (!!window.ActiveXObject || "ActiveXObject" in window);
    var isIE9More = (! -[1, ] == false);
    function reinitIframe(iframeId, minHeight) {
        try {
            var iframe = document.getElementById(iframeId);
            var bHeight = 0;
            if (isChrome == false && isSafari == false)
                bHeight = iframe.contentWindow.document.body.scrollHeight;
    
            var dHeight = 0;
            if (isFireFox == true)
                dHeight = iframe.contentWindow.document.documentElement.offsetHeight + 2;
            else if (isIE == false && isOpera == false)
                dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
            else if (isIE == true && isIE9More) {//ie9+
                var heightDeviation = bHeight - eval("window.IE9MoreRealHeight" + iframeId);
                if (heightDeviation == 0) {
                    bHeight += 3;
                } else if (heightDeviation != 3) {
                    eval("window.IE9MoreRealHeight" + iframeId + "=" + bHeight);
                    bHeight += 3;
                }
            }
            else//ie[6-8]、OPERA
                bHeight += 3;
    
            var height = Math.max(bHeight, dHeight);
            if (height < minHeight) height = minHeight;
            iframe.style.height = height + "px";
        } catch (ex) { }
    }
    function startInit(iframeId, minHeight) {
        eval("window.IE9MoreRealHeight" + iframeId + "=0");
        window.setInterval("reinitIframe('" + iframeId + "'," + minHeight + ")", 100);
    }
    
  • 相关阅读:
    IOS断点下载
    IOS中手机、pad的坐标系
    修改UINavigationController返回按钮的标题及如何隐藏导航栏
    备份数据脚本
    判断apache是否启动的脚本
    MySQL utf8mb4 字符集:支持 emoji 表情符号
    opacity兼容写法
    返回顶部(解决IE6固定定位)
    CSS3字体图标
    css3旋转小三角
  • 原文地址:https://www.cnblogs.com/wei-dong/p/6542820.html
Copyright © 2020-2023  润新知