如何关闭asp.net中的当前选项卡? [英] How do I close the current tab in asp.net?

查看:68
本文介绍了如何关闭asp.net中的当前选项卡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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



How do I close the current tab in asp.net? It works in IE but not in Firefox or Chrome.

I also publish the code and run it cannot run.

<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>

推荐答案

请参阅我对该问题的评论。有关更多背景信息,请参阅我最近的回答:如何使用Jquery或Javascript关闭我当前的浏览器窗口 [ ^ ]。



我明白你的情况会有所不同,所以我们可以讨论一下。但是,通常, window.close()无法关闭当前选项卡;你不能用JavaScript关闭它,而且,我认为,出于某些原因。


-SA
Please see my comment to the question. For some more background, see also my recent answer: How I Can Close My Current browser Window Using Jquery or Javascript[^].

I do understand that your situation can be different, so we could discuss it. But, generally, window.close() cannot close a current tab; you just cannot close it with JavaScript, and, I think, for some good reasons.

—SA

这篇关于如何关闭asp.net中的当前选项卡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆