2010-10-27 68 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