0

How can I make a button that closes the browser? The code below doesn't work for my ASP.NET MVC Application. I've already tested it on Mozilla, Chrome and Edge.

<!DOCTYPE html>
<body>
    <input type="submit" id="btnCloseScreen" name="btnCloseScreen" value="X" style="font-size:large; font-weight:bold; background-color:red; width:30px; border-color:#3f464c; height:30px" />
</body>

    $("#btnCloseScreen").click(function () {

        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.open('', '_self', ''); window.close();
        }
    }
    </script>

OEZ BRO
  • 57
  • 7
  • 1
    Perhaps this may be of help to you? https://stackoverflow.com/questions/8890394/how-to-close-a-window-using-jquery – Cooper1810 Feb 24 '20 at 15:26
  • The Browser Debugger is giving me following feedback: "Scripts cannot close windows that they have not opened." – OEZ BRO Feb 24 '20 at 15:30

0 Answers0