Explosion Pills
Explosion Pills

Reputation: 191749

IE: Unset window.opener

I am trying to check whether a window on my site can be closed with:

if (window.opener && window.opener.closed === false) {

It is possible for users to reach my site via another window that sets window.opener. I can "reset" window.opener when users initially reach my site using: window.opener = null. However, this doesn't work in IE (on the next page, window.opener is restored).

Is there a way to "reset" the window.opener construct in IE, or another cross-browser solution to my problem in general?

Upvotes: 0

Views: 648

Answers (1)

Explosion Pills
Explosion Pills

Reputation: 191749

I found a solution that's not totally analogous, but will work for my purposes. I only want to close the window if the opener is from the same domain.

if (window.opener.location.hostname.indexOf(window.location.hostname) > -1) {

However, IE does not allow you to access window.opener.location if the opener is from a different host. This actually works out quite well:

try {
    //snippet above
}
catch (error) { /* no action needed; assume different host */ }

Upvotes: 1

Related Questions