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>

2
  • 1
    Perhaps this may be of help to you? stackoverflow.com/questions/8890394/… Commented Feb 24, 2020 at 15:26
  • The Browser Debugger is giving me following feedback: "Scripts cannot close windows that they have not opened." Commented Feb 24, 2020 at 15:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.