Why does IE throw an "access denied" error when trying to access any property of a popup window?
I have created a popup window (something) like this:
var win;
function po开发者_开发技巧pup() {
if (win) {
win.close();
win = null;
}
win = window.open(...);
}
That exact code, in a simple .html file, works just fine. However it causes problems in our web app. IE always throws an "access denied" exception when trying to access most any property of the already-opened popup. The URL I am opening is on the same server, so it shouldn't be an XSS problem.
Other browsers are fine with this.
Couple of things: 1. how do other browsers behave? 2. might there be an IE setting that allows/disallows this?
Not being able to see an example of the issue, the most likely cause I know if is trying to access the spawned window before it's loaded. You need to wait until the child window fires its onload event before accessing it's DOM. I usually fire a callback defined in the parent window, from a body onload handler in the child window, to let the parent know it's safe to manipulate that window. The reason it's only happening in your "web app" could be that you have extra latency with a remote server that causes it to take longer to load the child.
精彩评论