Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/468.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 iframe使用可扩展内容自动调整大小_Javascript - Fatal编程技术网

Javascript iframe使用可扩展内容自动调整大小

Javascript iframe使用可扩展内容自动调整大小,javascript,Javascript,我有一个我正在构建的页面,它需要使用iframe,这样我们就可以在内容周围有一个包装器,也可以在没有包装的情况下显示它。我已经找到了一些能够自动检测iframe高度的JS,但是其中的内容会扩展,而iframe无法识别这一点。我假设我需要在框架内容中找到某种类型的onclick,它将触发iframe再次调整大小,但到目前为止已经被卡住了 下面是我在head部分中为自动调整iframe大小的函数提供的JS: <script type="text/JavaScript"> f

我有一个我正在构建的页面,它需要使用iframe,这样我们就可以在内容周围有一个包装器,也可以在没有包装的情况下显示它。我已经找到了一些能够自动检测iframe高度的JS,但是其中的内容会扩展,而iframe无法识别这一点。我假设我需要在框架内容中找到某种类型的onclick,它将触发iframe再次调整大小,但到目前为止已经被卡住了

下面是我在head部分中为自动调整iframe大小的函数提供的JS:

<script type="text/JavaScript">



    function autoResize(id){
        //alert('check');
        var newheight;
        var newwidth;

        if(document.getElementById){
            newheight=document.getElementById(id).contentWindow.document .body.scrollHeight;
            newwidth=document.getElementById(id).contentWindow.document .body.scrollWidth;
        }
        //alert(newheight);
        //alert(newwidth);
        document.getElementById(id).height= (newheight) + "px";
        document.getElementById(id).width= (newwidth) + "px";

    }


    </script>

函数自动调整大小(id){
//警惕(“检查”);
var newheight;
新宽度;
if(document.getElementById){
newheight=document.getElementById(id).contentWindow.document.body.scrollHeight;
newwidth=document.getElementById(id).contentWindow.document.body.scrollWidth;
}
//警报(新高度);
//警报(新宽度);
document.getElementById(id).height=(newheight)+“px”;
document.getElementById(id).width=(newwidth)+“px”;
}
然后这是带有onload和ID的iframe:

<iframe id="showcase" src="index.html" onload="javascript: autoResize('showcase');" frameborder="0" width="800px" height="4000" scrolling="no"></iframe>


感谢您的帮助,我希望我在这个问题上已经足够具体。

我不确定,但我假设您可以使用设置帧内对象的
body
属性的
offsetWidth
/
offsetHeight
事件处理程序,并调用
autoResize


同样,我也不确定这是否可行。

您真的不能使用AJAX实现这一目的吗?