开发者

javascript iframe permission

I have a webpage (parent) on localhost, with an iframe showing another url (child; which is part of a different webapp) on localhost.

Using javascript in parent-page, I am trying to "peek" into the iframe.contentDocument. (The iframe is showing a list of items, and if the list is empty, I simply want to hide the iframe completely.)

Now, the problem is, when trying to retrieve the element iframe.contentDocument.body, I get error-msg in firefox: Permission denied to access property 'body'

In IE, I simply 开发者_JS百科get: Error: 'body' is null or not an object.

Anyone, knows how to get around this?

Thanks,


I've seen two potential work-arounds for this error where body returns null. One is to simply bury your script at the bottom of the body, so that it doesn't execute before body has been built out. But everybody hates inline scripts, no?

Another, from here, is to use an onload function for your body, which also ensures that body exists before the function is called.

Both seem to work equivalently well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜