Close Current Tab In A Browser Window Using JavaScript
Here we consider how to Close Current Tab In A Browser Window.
We can close only those tab which are opened by JavaScript.
For opening a tab, we can use following code.
var ww = window.open(window.location, '_blank');
For closing this tab, we can use window.close();
Here is an example.
<a href="#" onclick="CloseWindow();return false;">close</a>
function CloseWindow() {
if (confirm("Close Window?")) {
close();
}
}
When the user click on the link, he will get a warning.
If the user permit, the tab will be closed using window.close().