How to find out if a window can be closed using js
So, as said elsewhere, the window can be closed using js window.close()
only if the script was open.
I have a page that offers a button to open a discussion window. The discussion window opens to a new tab with window.open()
. The talk page has a trigger button window.close()
that closes the talk window and takes you back to the previous tab, so you can pick up where you left off.
The problem is if someone grabs the url directly from the talk window, the close button doesn't work.
Is there a way to determine if the window will close with window.close()
so I can only show the button if it works?
source to share
You can check if window.opener
not null
:
When a window is opened from another window, it maintains a link to that first window as window.opener. If there is no opener in the current window, this method returns NULL. Windows Phone browser does not support window.opener. It is also not supported in IE if the opener is in a different security zone.
source to share