admin管理员组文章数量:1349674
I have done some research, but as a JavaScript novice, I can't seem to get anything to work for my specific case:
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;
In the parent document I have:
<h4 id="slidecaptionOoH"></h4>
I've tried putting a ment 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.
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.
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?
I have done some research, but as a JavaScript novice, I can't seem to get anything to work for my specific case:
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;
In the parent document I have:
<h4 id="slidecaptionOoH"></h4>
I've tried putting a ment 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.
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.
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?
Share Improve this question edited Oct 20, 2011 at 18:12 sharcupine asked Oct 20, 2011 at 16:56 sharcupinesharcupine 1151 gold badge2 silver badges12 bronze badges 7- have you tried parentNode instead of parent? – amosrivera Commented Oct 20, 2011 at 17:03
-
@amosrivera —
window.parent
is the parent frame.window.parentNode
doesn't exist unless you create it. – Quentin Commented Oct 20, 2011 at 17:12 - I just tried it and it results in 'parenNode' is undefined. – sharcupine Commented Oct 20, 2011 at 17:12
- 2 Are the pages on the same domain, port and protocol? – mplungjan Commented Oct 20, 2011 at 17:25
- @Quentin — I've tried window.parent and top.parent, and I still get the "null or not an object" error. – sharcupine Commented Oct 20, 2011 at 17:27
1 Answer
Reset to default 3You 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.
本文标签: javascriptparentdocumentgetElementById(quotquot) is null or not an object in IE7Stack Overflow
版权声明:本文标题:javascript - parent.document.getElementById("...") is null or not an object in IE7 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743867387a2552830.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论