Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/477.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.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调用父函数,关于iframe调整大小函数_Javascript_Php_Html_Iframe_Resize - Fatal编程技术网

Javascript 从iframe调用父函数,关于iframe调整大小函数

Javascript 从iframe调用父函数,关于iframe调整大小函数,javascript,php,html,iframe,resize,Javascript,Php,Html,Iframe,Resize,让我们从iframe中调整iframe的大小,并从中获得乐趣 因此,我有一个html页面,其中包含一些代码,可以在加载iframe时调整其大小。javascript位于头部,看起来如下所示: <script type="text/javascript"> <!-- function resizeIframe(id){ /* this.obj=obj //this.obj.width=null //this.obj.width=window.frames["sizeframe"]

让我们从iframe中调整iframe的大小,并从中获得乐趣

因此,我有一个html页面,其中包含一些代码,可以在加载iframe时调整其大小。javascript位于头部,看起来如下所示:

<script type="text/javascript">
<!--
function resizeIframe(id){
/*
this.obj=obj
//this.obj.width=null
//this.obj.width=window.frames["sizeframe"].document.body.scrollWidth
this.obj.style.height="" // for Firefox and Opera
setTimeout("this.obj.style.height=this.obj.contentWindow.document.body.scrollHeight+(notIE?heightOffset:0)",10) // setTimeout required for Opera
*/

el=document.getElementById(id)
el.style.height="350px" // for Firefox and Opera
setTimeout("el.style.height=el.contentWindow.document.body.scrollHeight+'px'",1) // setTimeout required for Opera
}

// -->
</script>
<iframe name="sizeframe" src="thoughtsinitialview.php" marginwidth="1" marginheight="1" width="596" align="middle" border="0" frameborder="0" onload="resizeIframe(this.id)" id="sizeframe" allowTransparency="true" scrolling="no">
print "<script type='text/javascript'>
function AutoGrowTextArea(textField){
    if(textField.clientHeight<textField.scrollHeight){
        textField.style.height = textField.scrollHeight + 'px';
        if(textField.clientHeight < textField.scrollHeight){
            textField.style.height = (textField.scrollHeight * 2 - textField.clientHeight) + 'px';
        }
    }
}
</script>";
<textarea name='reply' id='reply' rows='1' style=width: 350' onKeyUp='AutoGrowTextArea(this)'>Write a comment...</textarea>
parent.resizeIframe(id)
+++但是,它不起作用。我尝试了所有我能想到的组合,但我没有这里的巫师们聪明

怎么做?做我当textarea根据用户输入调整大小时,是否调整iframe的大小

提前向你表示感谢和业力祝福!(这是针对站点:sitempty.org)

1)resizeIframe中的高度不是动态的,而是静态的350px。2) 如果父站点来自不同的域(相同的域策略),则无法调整iframe的大小。1)350px是iframe的起始高度,然后调整大小。2) 您确定无法从iframe中调整iframe的大小吗?(我之所以这么问,是因为可以从iframe中调用其他父javascript函数…)3)解决方案中有什么想法吗?好的,3)settimeout不起作用,因为执行的代码在新的(不同的)范围内;因此像
el
这样的局部变量不存在;如果未定义
el
,您将收到一个javascript警报。对于父函数调用:如果两个站点位于同一个域上,则该调用有效。如果不是,它不会。那么事件处理程序“OnResize”呢……请查看sitempty.org上的“想法”页面……有证据表明resize-iframe确实有效……我从2009年起就一直在使用该代码……从mtmj.org到许多其他网站,它都有效。我想也许我没有发布所有的代码,所以这是玉米引信。。。