Reputation: 455
I want to close a tab after getting confirmation from user. It can be done as follow-
window.onbeforeunload = function() {
return "Are you sure?";
}
But the problem with this code is that it shows some message that I am not expecting. I want to do this task using javascript's confirm() popup. can anyone help me to do this.
Thanks in advance.
Upvotes: 0
Views: 247
Reputation: 1054
function closewindow() {
if (confirm("Are you sure?")) {
window.close();
}
}
Upvotes: 0
Reputation: 14243
This is really the only way to handle this. The software companies that created these browsers went to great lengths to make sure this could not be abused, and this is the solution they came up with. You can't trigger any custom javascript beyond providing a string that the browser handles, when the user closes the browser.
Upvotes: 2