I need to be able to check if I can close the current page, however since it returns the warning "Scripts may close only the windows that were opened by them." It wont be caught by a try/catch statement because it isn't an "error". Is there any way I can get around this?
function attemptToClose() {
try {
window.close();
}
catch(err) {
//do something different
console.log(err)
}
}
If I understand this correctly window.close();
can only close pages open by itself aka window.open();
.
This might be a security prevention method so that websites do not take control of your browsers.
Try initiating the page with window.open();
then try using the window.close();
.
Hope this solves it!