内部嵌套2层frame. frame无滚动条, window高度根据frame网页高度自适应javascript.

_______________________________________________

|___________________1__________________________|

|         |                                                                                     |            |

|    2   |                         3                                                          |       4  |

|         |                                                                                     |            |

|____|_____________________________________|_____|

3+4 = frame1, 3= frame2

自适应代码:

function SetWindowHeight(obj)
{    
    var win=obj;
    if (document.getElementById)
    {
        if (win && !window.opera)
        {
            if (win.contentDocument && win.contentDocument.body.offsetHeight){
                    win.height = win.contentDocument.body.offsetHeight; // firefox?
                    if(win.height<670)
                        win.height = 670;
                    $(window.parent.parent.document).find("#frame1").attr("height", win.height);
            }
            else if(win.Document && win.Document.body.scrollHeight){
                    win.height = win.Document.body.scrollHeight; // ie?
                    if(win.height<670)
                        win.height = 670;
                    $(window.parent.parent.document).find("#frame1").attr("height", win.height);
            }
        }
    }
    window.parent.parent.document.body.scrollTop = 0;
}

另一段调整高度代码:

function setHeight1(){
        if(navigator.appName == 'Microsoft Internet Explorer') {
            var centerFrame = parent.document.getElementById("frame1");
            var height = centerFrame.contentWindow.document.documentElement.scrollHeight;
                height = height - $("#aaa").height();
            centerFrame.height = height;
            parent.parent.document.getElementById("frame1").height = height;
        }else{
            var centerFrame = parent.document.getElementById("centerFrame");
            var height = centerFrame.contentWindow.document.body.scrollHeight;
            height = height - $("#aaa").height();
            centerFrame.height = height;
            parent.parent.document.getElementById("content").height = height;
        }
    }

    function setHeight2(){
        if(navigator.appName == 'Microsoft Internet Explorer') {
            var centerFrame = parent.document.getElementById("frame2");
            var height = centerFrame.contentWindow.document.documentElement.scrollHeight;
            centerFrame.height = height;
            parent.parent.document.getElementById("frame1").height = height;
        }else{
            var centerFrame = parent.document.getElementById("frame2");
            var height = centerFrame.contentWindow.document.body.scrollHeight;
            centerFrame.height = height;
            parent.parent.document.getElementById("frame1").height = height;
        }
    }


你可能感兴趣的:(function,Microsoft,internet)