views:

36

answers:

1

Hi,

I have the following seems to work in Internet Explorer but not Chrome. Can anyone please explain why, and what I should do to correct it.

<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>

The script should automatically extend the height of the iframe to fit the contents. Internet Explorer gets the value right, however Chrome seems to calculate the value massively incorrectly.

Any ideas?

+3  A: 

Take another good look what's happening here:

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

In this event handler, confirmed_list was never defined. I'm sure you mean document.getElementById( 'confirmed_list' ) here.

Anyway, a better solution is to use this, as it refers to the iframe:

this.height = this.document.body.scrollHeight
Harmen
+1 for `this` ` `
Pekka
Hehe, Pekka, you are _always_ about thirty or more seconds faster than I am ;)
Harmen
Again breaks the code even more. onLoad calls after the iframe has loaded, thus the html element exists? (forgive me if that's wrong)
Ian Cant
Ugh. Chrome seems to have *yet another* different way to access the contentDocument. Deleting my answer, I'm too lazy to research this right now :)
Pekka