首页 > 其他 > 详细

异步操作执行后子页面重新修改父页面iframe高度

时间:2016-06-04 20:52:49      阅读:96      评论:0      收藏:0      [点我收藏+]

子页面加入ajax全局方法:

<script language="javascript" type="text/javascript">
        $(document).ready(function () {//异步请求加载完成
            $.ajaxSetup({
                complete: function () {
                    //修改iframe高度
                    reSizeParentIframe();
                }
            });
        });        
    </script>

修改iframe高度:

//子页面重新修改父页面iframe高度
function reSizeParentIframe() {
    var realHeight = 0;
    if (navigator.userAgent.indexOf("Firefox") > 0 || navigator.userAgent.indexOf("Mozilla") > 0 || navigator.userAgent.indexOf("Safari") > 0 || navigator.userAgent.indexOf("Chrome") > 0) { // Mozilla, Safari,Chrome, ...  
        realHeight = window.document.documentElement.offsetHeight + 35; 
    } else if (navigator.userAgent.indexOf("MSIE") > 0) { // IE  
        var bodyScrollHeight = window.document.body.scrollHeight + 21; //取得body的scrollHeight  
        var elementScrollHeight = window.document.documentElement.scrollHeight + 1; //取得documentElement的scrollHeight  
        realHeight = Math.max(bodyScrollHeight, elementScrollHeight); //取当中比较大的一个  
    } else {//其他浏览器  
        realHeight = window.document.body.scrollHeight + window.document.body.clientHeight + 1;
    }
    if (realHeight < 400) {
        realHeight = 400;
    }
    if ($("#ifm", window.parent.document).is("iframe")) {
        $("#ifm", window.parent.document).height(realHeight);
    }
}

 参考:http://www.cnblogs.com/shenyixin/archive/2013/03/05/2943892.html

异步操作执行后子页面重新修改父页面iframe高度

原文:http://www.cnblogs.com/zhang-2052975439/p/5559435.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!