开发者

javascript iframe permission

开发者 https://www.devze.com 2023-04-11 19:11 出处:网络
I have a webpage (parent) on localhost, with an iframe showing another url (child; which is part of a different webapp) on localhost.

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

精彩评论

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

关注公众号