×

Index

JavaScript Tutorial

JavaScript Examples

CSS Tutorial

CSS Examples

JavaScript - Close Current Tab on Button Click with Confirmation

In this code snippet we will learn how to close current tab on button click event with confirmation box. Here we will implement JavaScript function to close current tab with confirmation box.

Close Current Tab with Confirmation Box

JavaScript function:

<script type="text/javascript">
    function closeCurrentTab() {
        var conf = confirm("Are you sure, you want to close this tab?");
        if (conf == true) {
            close();
        }
    }
</script>

JavaScript and HTML Code to Close Current Tab on Button Click with Confirmation

<!--JavaScript - Close Current Tab on Button Click with Confirmation.-->
<html>
    <head>
        <title>JavaScript - Close Current Tab on Button Click with Confirmation.</title>
        <script type="text/javascript">
            function closeCurrentTab() {
                var conf = confirm("Are you sure, you want to close this tab?");
                if (conf == true) {
                    close();
                }
            }
        </script>
    </head>

    <body style="text-align: center;">
        <h1>JavaScript - Close Current Tab on Button Click with Confirmation.</h1>
        <p><input type="button" value="Close Tab." onclick="closeCurrentTab()"></p>
    </body>
</html>

Result

close current tab using javascript

JavaScript Examples »



Related Examples



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.