I have a site that opens another tab/window temporarily. Once it's no longer relevant or needed, its script calls window.close(). However, the user may occasionally have that URL bookmarked or access it in some other way manually rather than arriving there as the result of the first/main window programmatically opening it.
In such cases, I note that the .close() call results in a warning on the console (Chrome 48). I understand it's a security feature, and am totally fine with that.
What I'd like to do is to detect that the call didn't work (or won't) and do something else instead - in my case show the user a flash message saying they should close the tab/window manually.
I tried the below code, but am realizing that since no exception was thrown, the catch is never hit. Is there a way to do what I'm wanting to?
try {
window.close();
}
catch (e) {
showFlashMessage('Error closing tab. Please close it manually.'); // Never gets here :(
}