Reputation: 191749
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
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