NETMVC;Javascript;HTML:如何制作自己的关闭浏览器的按钮?

NETMVC;Javascript;HTML:如何制作自己的关闭浏览器的按钮?,javascript,html,asp.net-mvc,model-view-controller,Javascript,Html,Asp.net Mvc,Model View Controller,如何制作关闭浏览器的按钮?下面的代码不适用于我的ASP.NET MVC应用程序。我已经在Mozilla、Chrome和Edge上测试过了 <!DOCTYPE html> <body> <input type="submit" id="btnCloseScreen" name="btnCloseScreen" value="X" style="font-size:large; font-weight:bold; background-color:red; wi

如何制作关闭浏览器的按钮?下面的代码不适用于我的ASP.NET MVC应用程序。我已经在Mozilla、Chrome和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>


$(“#btnCloseScreen”)。单击(函数(){
var Browser=navigator.appName;
var indexB=Browser.indexOf('Explorer');
如果(indexB>0){
var indexV=navigator.userAgent.indexOf('MSIE')+5;
var Version=navigator.userAgent.substring(indexV,indexV+1);
如果(版本>=7){
窗口。打开(“”,“”,“”);
window.close();
}
否则如果(版本==6){
window.opener=null;
window.close();
}
否则{
window.opener='';
window.close();
}
}
否则{
window.open(“”,“”,“”);window.close();
}
}

这可能对您有所帮助?浏览器调试器给了我以下反馈:“脚本无法关闭尚未打开的窗口。”