基于子内容滚动高度的响应iframe高度

时间:2017-02-14 14:11:01

标签: javascript jquery iframe responsive

我想知道我是否可以使用iframe高度执行某些操作,因此iframe不会有任何滚动条。是否可以通过jQuery从它的父亲那里读取iframe上的html滚动高度?我相信如果子源来自同一个原始域,这应该是可能的。

我试图通过控制台读取孩子,并显示正确的内容高度:

$('iframe')[0].contentWindow.document.body.clientHeight

enter image description here

但我如何将它实现给父母js,这里是代码:

$('#responsive-toolbar ul li a').on('click',function(){

    var target = $(this).data('responsive');
    $(this).parent().addClass('active').siblings().removeClass('active');

    if(target == 'phone'){
        $('iframe').css({'width':480});
        newHeight =  $('iframe')[0].contentWindow.document.body.clientHeight;
        $('iframe').css({'height':newHeight});
    } else {
        $('iframe').css({'width':640});
        newHeight =  $('iframe')[0].contentWindow.document.body.clientHeight;
        $('iframe').css({'height':newHeight});
        }
});

0 个答案:

没有答案
相关问题