2

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>
Ajay2707
  • 5,690
  • 6
  • 40
  • 58
  • You also need to format this correctly and make it clear which part of the code you don't understand or what error message you are getting else it would be closed on SO – mmmmmm Jul 07 '15 at 11:55
  • 1
    Most browsers do not allow webpages to unilaterally close browser windows. Furthermore there is no in-browser API to control browser tabs, only the concept of a "window". – Dai Jul 09 '15 at 07:26
  • no error message it did not close tab – senthilnathan Jul 10 '15 at 03:15
  • possible duplicate of [Close Current Tab](http://stackoverflow.com/questions/14373625/close-current-tab) – Quentin Sep 07 '15 at 10:41

0 Answers0