異步操作執行后子頁面重新修改父頁面iframe高度


子頁面加入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);
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM