首页 > 解决方案 > ASP.NET MVC;Javascript;HTML:如何制作一个关闭浏览器的自己的按钮?

问题描述

如何制作关闭浏览器的按钮?下面的代码不适用于我的 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>

标签: javascripthtmlasp.net-mvcmodel-view-controller

解决方案


推荐阅读