parent.document.getElementById(" ...")为null或不是IE7中的对象 [英] parent.document.getElementById("...") is null or not an object in IE7

查看:622
本文介绍了parent.document.getElementById(" ...")为null或不是IE7中的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一些研究,但作为一个JavaScript新手,我似乎无法为我的具体案例工作:

I have done some research, but as a JavaScript novice, I can't seem to get anything to work for my specific case:

我有一个iframe in一个页面,在那个iframe的文档中,我有以下代码:

I have an iframe in a page, and in that iframe's document, I have the following code:

function fun(){
var slideTitle = api.getField('title');
    parent.document.getElementById("slidecaptionOoH").innerHTML = slideTitle;

在父文档中我有:
< h4 id =slidecaptionOoH>< / h4>

我试过在标签之间添加评论,但我仍然得到了IE7中的错误。页面显示正常,但显然我不希望别人看到错误。

I've tried putting a comment in between the tags, but I still get the error in IE7. The page displays fine, but obviously I don't want people to see the error.

好吧,我想我我把这个问题缩小了一点。我认为它可能与iframe文档在父完成加载之前执行的函数有关。我在父级中使用了treesaver.js框架,这涉及到繁重的DOM操作。当我关闭treeaver时,我不再收到错误。

Well, I think I've narrowed down the problem a bit. I think it may have to do with the iframe document's function executing before the parent is finished loading. I'm using the treesaver.js framework in the parent, which involves heavy DOM manipulation. When I turn off treesaver, I no longer receive the error.

所以我想我现在的问题是,如何延迟函数直到父完成加载?或者延迟加载iframe文档?

So I guess my question now is, how do I delay the function until the parent is finished loading? Or delay the loading of the iframe document altogether?

推荐答案

您可以继续汇集父级,直到它加载了相应的子级为:

You can keep pooling the parent until it has loaded the respective child with:

function fun(){
    var slideTitle = api.getField('title');
    var el = parent.document.getElementById("slidecaptionOoH");
    if (el){
        el.innerHTML = slideTitle;
    } else{
        setTimeout(fun, 50);
    }
    el = null;
}

但这只是一个(污垢)工作。

But this is just a(dirt) work around.

这篇关于parent.document.getElementById(&quot; ...&quot;)为null或不是IE7中的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆