Close Internet Explorer without Confirm Prompt through JavaScript

 

You can easily close the browser through javascript, but it will give some confirmation prompt in Internet Explorer(IE) browser.  In all other browsers we won't get any Confirm Prompt.

 

In this article we discuss about how to close the IE browser without any confirmation prompt. First we will see how can we close the browser on button click simply.

 

<html>

<head>

    <title></title>

    <script type="text/javascript">

        function closeWindow() {

            window.close();

        }

    </script>

</head>

<body>

    <input type="button" value="Click" onclick="closeWindow();" />

</body>

</html>

 

As shown above we are calling windo.close() method on button click. When you click on button click we will get the confirm prompt as shown below.

 

                   

 

To remove the confirm prompt on button click change the closeWindow() function as shown below.

 

<html>

<head>

    <title></title>

    <script type="text/javascript">

        function closeWindow() {

            var Browser = navigator.appName;

            var indexB = Browser.indexOf('Explorer');

 

            if (indexB > 0) {

                var indexV = navigator.userAgent.indexOf('MSIE') + 5;

                var Version = navigator.userAgent.substring(indexV, indexV + 1);

 

                if (Version >= 7) {

                    window.open('', '_self', '');

                    window.close();

                }

                else if (Version == 6) {

                    window.opener = null;

                    window.close();

                }

                else {

                    window.opener = '';

                    window.close();

                }

            }

            else {

                window.close();

            }

        }

    </script>

</head>

<body>

    <input type="button" value="Click" onclick="closeWindow();" />

</body>

</html>

 

If you click the Close button now, it won't ask any confirmation prompt in Internet Explorer browser or IE browser.

 

                                                                                                            TestCloseFunctionality.zip (497.00 bytes)