Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jQuery事件调整contentWindow高度_Javascript_Jquery - Fatal编程技术网

Javascript 使用jQuery事件调整contentWindow高度

Javascript 使用jQuery事件调整contentWindow高度,javascript,jquery,Javascript,Jquery,到目前为止,我通过这篇文章得到了以下信息: 问题是函数resizeIframe()在再次调用后似乎没有任何变化。帧大小不变 这是我的全部代码: function resizeIframe(obj) { obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px'; } $(document).ready(function() { // change iframe based on drop down m

到目前为止,我通过这篇文章得到了以下信息:

问题是函数
resizeIframe()
在再次调用后似乎没有任何变化。帧大小不变

这是我的全部代码:

function resizeIframe(obj) {
    obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
}

$(document).ready(function() {

// change iframe based on drop down menu //

    $('#dropdown').click(function(){
        $('iframe').slideUp("slow");
        $('iframe').attr('src', 'preview.php?frame=off&sid='+$(this).val());
        resizeIframe(document.getElementById('previewframe'));
        $('iframe').slideDown('slow');
    });
}
这是我的HTML

<iframe id="previewframe" src="preview.php?frame=off&sid=1" style="width: 100%; overflow-x: hidden; overflow-y: scroll" onload='javascript:resizeIframe(this);'>
</iframe>
然后我的主文件中有以下内容:

<iframe name="previewframe" id="previewframe" src="preview.php?frame=off&sid=1" style="width: 100%; overflow-x: hidden; overflow-y: scroll;">
</iframe>
<script type="text/javascript">
    function AdjustIframeHeight(i) {
        alert("CHANGING: " + parseInt(i));
        document.getElementById('previewframe').style.height = parseInt(i) + "px";
        alert("Current value: " + document.getElementById('previewframe').style.height);
    }
</script>

它将完美地工作。因此,这让我相信浏览器只是需要以某种方式更新设置的高度。

我遇到了这个问题。下面是我如何使它工作的

myiframe.css('visibility', 'hidden' );
myiframe.css('height', '1px' );
myiframe.css('height', myiframe.contents().height() ); // get the size of the iframe content height.
myiframe.css('visibility', 'visible' );

我想把它藏起来,让它可见是不可能的,但这不是唯一的办法。我从document.getElementById(id).style.height切换到myiframe.css(),它成功了。

我能够使用这个框架获得我想要的解决方案

我的主文件包含以下代码:

<iframe id="previewframe" src="preview.php?frame=on&sid=1" style="width: 100%; overflow-x: hidden; overflow-y: scroll;"></iframe>

<script type="text/javascript">
    $('iframe').iFrameResize({
        log                     : false,   // Enable console logging
        enablePublicMethods     : true,    // Enable methods within iframe hosted page
        resizedCallback: function (obj) {
            $('iframe').slideUp("slow");
            $('iframe').slideDown("slow");
        }
    });
</script>

$('iframe')。iframesize({
日志:false,//启用控制台日志记录
enablePublicMethods:true,//在iframe托管页面中启用方法
resizedCallback:函数(obj){
$('iframe').slideUp(“slow”);
$('iframe')。向下滑动(“慢速”);
}
});
我的框架有这个代码

     <script type="text/javascript" src="js/iframeResizer.contentWindow.min.js"></script>
     <script>
        var please = function(){
          if ('parentIFrame' in window){
            parentIFrame.setHeightCalculationMethod('max'); 
          }
        };
    </script>
</body>

var=function(){
if(窗口中的“parentIFrame”){
parentIFrame.setHeightCalculationMethod('max');
}
};
真管用

<iframe id="previewframe" src="preview.php?frame=on&sid=1" style="width: 100%; overflow-x: hidden; overflow-y: scroll;"></iframe>

<script type="text/javascript">
    $('iframe').iFrameResize({
        log                     : false,   // Enable console logging
        enablePublicMethods     : true,    // Enable methods within iframe hosted page
        resizedCallback: function (obj) {
            $('iframe').slideUp("slow");
            $('iframe').slideDown("slow");
        }
    });
</script>
     <script type="text/javascript" src="js/iframeResizer.contentWindow.min.js"></script>
     <script>
        var please = function(){
          if ('parentIFrame' in window){
            parentIFrame.setHeightCalculationMethod('max'); 
          }
        };
    </script>
</body>