我将如何关闭当前选项卡

时间:2015-07-07 11:02:25

标签: javascript asp.net

如何关闭asp.net中的当前选项卡?它适用于IE,但不适用于Firefox或Chrome。

我也发布代码并运行它无法运行。

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script language="javascript" type ="text/javascript"  >
        function closeMe() {
       // alert('1')
         //   setInterval( closeMe1() , 5000);
            var win = window.open("", "_self");

            win.close();
        }
        function closeMe1() {
        alert('2')
            var win = window.open("", "_self");

            win.close();

        }
        function closemefire() {
        alert('f')
        var Browser = navigator.appName;
        alert(Browser)
        var indexB = Browser.indexOf('Explorer');
        alert(indexB)
            if (indexB > 0) {

                var indexV = navigator.userAgent.indexOf('MSIE') + 5;
                var Version = navigator.userAgent.substring(indexV, indexV + 1);

                if (Version >= 7) {
                alert('sdf')
                    window.open('', '_self', '');
                    window.close();
                }
                else if (Version == 6) {
                alert('dhgf')
                    window.opener = null;
                    window.close();
                }
                else {
                    alert('dhgf1')
                    window.opener = '';
                    window.close();
                }
            }
            else {
                alert('dhgf2')
                window.close();
            }
        }
        function closeWindow() {
//            window.open('', '_parent', '');
            window.close();
        } 
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Button runat="server" text="Close Me" OnClientClick ="closeMe()" ID="CloseMe" />
    <asp:Button runat="server" text ="Fire CloseMe"  OnClientClick ="closemefire()" ID="Button1" />
     <asp:Button runat="server" text ="Fire1 CloseMe"  OnClientClick ="closeWindow()" ID="Button2" />
    </div>
    </form>
</body>
</html>

0 个答案:

没有答案