2010-10-27 78 views
0

我有以下似乎工作在Internet Explorer但不是铬。任何人都可以请解释为什么,以及我应该怎样做才能纠正它。风格和Javascript不工作

<iframe id="confirmed_list" src="./meets/confirmed.php?meet_id=$1" scrolling="no" width="80%" onload="document.getElementById('confirmed_list').height = confirmed_list.document.body.scrollHeight"> 
</iframe> 

该脚本应自动扩展iframe的高度以适合内容。 Internet Explorer的价值是正确的,但Chrome浏览器似乎大量计算错误值。

任何想法?

回答

3

再举一个好好看看这里发生了什么:

document.getElementById('confirmed_list').height = confirmed_list.document.body.scrollHeight 

在此事件处理程序,confirmed_list从未定义。我相信你的意思是document.getElementById('confirmed_list')这里。

无论如何,一个更好的解决方案是使用this,因为它指的iframe:

this.height = this.document.body.scrollHeight 
+0

呵呵,佩卡,你_always_约三十多秒的速度比我;) – Harmen 2010-10-27 18:08:35

+0

再次打破了代码更。在加载iframe之后onLoad调用,因此html元素存在? (原谅我,如果这是错误的) – 2010-10-27 18:10:37

+0

呃。 Chrome似乎有*另一种*不同的方式来访问contentDocument。删除我的答案,我懒得研究这个现在:) – 2010-10-27 18:21:13