iframe自适应子页面高度

作者: DarlingHH | 来源:发表于2017-04-10 20:37 被阅读0次

    <iframe id="iframeTable"  name="iframeTable"  scrolling="no" frameborder="0"  style="padding:0px; width:100%; height:100px;">

    </iframe>

    <script>

    $(document).ready(function(){

    startInit('iframeTable', 360);

    })

    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"inwindow);

    var isIE9More = (! -[1, ] ==false);

    function reinitIframe(iframeTable, minHeight) {

    try{variframe =document.getElementById(iframeTable);

    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+varheightDeviation = bHeight - eval("window.IE9MoreRealHeight" +iframeTable);

    if(heightDeviation == 0) {

    bHeight+= 3;

    else if(heightDeviation != 3) {

    eval("window.IE9MoreRealHeight" + iframeTable+ "=" +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(iframeTable, minHeight) {

    eval("window.IE9MoreRealHeight" + iframeTable+ "=0");

    window.setInterval("reinitIframe('" + iframeTable+ "'," + minHeight + ")", 100);

    }

    </script>

    相关文章

      网友评论

        本文标题:iframe自适应子页面高度

        本文链接:https://www.haomeiwen.com/subject/rdjeattx.html