Bruno
Bruno

Reputation: 4527

Problem closing popup window

I'm creating a popup window using window.open that can be closed later by the opener with a call to close() without problem, the problem is when the popup window navigates to a different url, then close() will do nothing.

I'm using IE9.

the code that I'm using to test is:

var popup = window.open($(this).attr("href"), "Popup", "width=550,height=300,toolbar=0,scrollbars=0,status=0,resizable=0,location=0,menuBar=0");
setTimeout(function () {
    popup.close();
}, 1000);

if the popup window doesn't navigate to another url, it closes, but if it does, it won't close...

thanks!

Upvotes: 1

Views: 427

Answers (1)

Dan Davies Brackett
Dan Davies Brackett

Reputation: 10081

This is a security feature, related to the single-origin policy. Once the domains of the opener and the openee no longer match, the browser will prevent things like close from working. It's just a fact of life, and one that that makes the web a less annoying place to be on the whole (at least from a security perspective).

Upvotes: 2

Related Questions