我的以下内容似乎适用于 Internet Explorer,但不适用于 Chrome。谁能解释一下原因,以及我应该采取什么措施来纠正它。
<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 似乎严重错误地计算了该值。
有什么想法吗?
最佳答案
再仔细看看这里发生了什么:
document.getElementById('confirmed_list').height = confirmed_list.document.body.scrollHeight
在此事件处理程序中,从未定义过confirmed_list
。我确定您指的是 document.getElementById( 'confirmed_list' )
。
无论如何,更好的解决方案是使用 this
,因为它引用 iframe:
this.height = this.document.body.scrollHeight
关于javascript - 样式和 JavaScript 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4036213/