• jquery iframe高度自适应


     $(document).ready(function () {
                $("#test").load(function () {
                    var thisheight = $(this).contents().find("body").height() +10;
                    $(this).height(thisheight < 500 ? 500 : thisheight);
                });
    
            });

    很多管理系统中,都使用iframe进行信息内容的展示方式,或者作为主菜单的链接展示内容。

    使用iframe的问题就是自适应高度的问题。

    iframe自适应高度本身是很简单的方法,就是在页面加载完成后,重新计算一下高度即可。

    代码如下:

    //公共方法:设置iframe的高度以保证全部显示数据
    //function SetPageHeight() {
    //    var iframe = getUrlParam('ifname');
    //    var myiframe = window.parent.document.getElementById(iframe);
    //     iframeLoaded(myiframe);
    //}
    var iframeLoaded = function (iframe) {
        if (iframe.src.length > 0) {
            if (!iframe.readyState || iframe.readyState == "complete") {
                var bHeight = 
                iframe.contentWindow.document.body.scrollHeight;
                var dHeight = 
                iframe.contentWindow.document.documentElement.scrollHeight;
                var height = Math.max(bHeight, dHeight);
                iframe.height = height;
            }
        }
    }
    //分页时重新设置 iframe 高度 ; 修改后:iframe.name = iframe.id
    var reSetIframeHeight = function()
    {
        try {
            var oIframe = parent.document.getElementById(window.name);
            oIframe.height = 100;
            iframeLoaded(oIframe);
        }
        catch (err)
        {
            try {
             parent.document.getElementById(window.name).height = 1000;
              } catch (err2) { }
        }
    }
  • 相关阅读:
    12.数组三--数组的冒泡排序与快速排序
    11.数组二
    10.数组一
    Vue之组件与父子传值
    Django模型层
    面向对象的组合用法
    面向对象初识
    Python内置函数
    列表推导式,生成器表达式
    装饰器进阶
  • 原文地址:https://www.cnblogs.com/wangjunwei/p/4437683.html
Copyright © 2020-2023  润新知