How to Close Current Tab Using Javascript

We can programmatically close the current tab using javascript

Here , we add an a tag with onclick handler. We can also optionally provide a confirmation message too.

 1<html>
 2<script>
 3    function close_window() {
 4        if (confirm("Close Window?")) {
 5            window.open('', '_self').close();
 6        }
 7    }
 8</script>
 9
10<body>
11    <a href="" onclick="close_window()"> close </a>
12
13</body>
14
15</html>
comments powered by Disqus