Javascript 在Chrome中获取iframe文档

Javascript 在Chrome中获取iframe文档,javascript,google-chrome,Javascript,Google Chrome,我试图根据iframe的内容动态更改其高度 但是,它在最新版本的chrome中不起作用 文档在chrome中是“未定义的” 它在Firefox中运行良好 我做错了什么 <script> $(function() { $('#iframeid') .load( function() { try {

我试图根据iframe的内容动态更改其高度

但是,它在最新版本的chrome中不起作用

文档在chrome中是“未定义的”

它在Firefox中运行良好

我做错了什么

<script>
    $(function() {

        $('#iframeid')
                .load(
                        function() {

                            try {
                                var doc = this.contentDocument ? this.contentDocument
                                        : this.contentWindow.document;
                                alert(doc);
                            } catch (e) {
                                alert(e.message);
                            }
                        });

    });
</script>
<iframe frameborder="0" id="iframeid" src="iframesource2.html"
    height="1px"> </iframe>

$(函数(){
$(“#iframeid”)
.装载(
函数(){
试一试{
var doc=this.contentDocument?this.contentDocument
:this.contentWindow.document;
警报(doc);
}捕获(e){
警报(e.message);
}
});
});

对我来说似乎很管用。看一看

一些不应该真正改变任何事情的小变化:

$(function () {
    $('#iframeid').load(function () {
        try {
            var doc = this.contentDocument || this.contentWindow.document;
            alert(doc);
        } catch (e) {
            alert(e.message);
        }
    });
});