views:

38

answers:

2

I have created a popup window (something) like this:

var win;
function popup() {
  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.

A: 

Couple of things: 1. how do other browsers behave? 2. might there be an IE setting that allows/disallows this?

brismith
A: 

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.

sunetos
I'd say it's not a DOM/loading issue because:1. I'm not accessing the DOM and2. The popup window is always loaded when the .close() method runs
John Cromartie
Can you give a more complete example? As in, what qualifies as "trying to access most any property"?
sunetos
@sunetos I think there is a high chance that you are right. As a separate note, IE8 starts a new process with every tab / window and sometimes it is not created in the same session as the parent for some unknown reasons. In those cases access denied will happen too.
airmanx86