Sunday, August 7, 2011

How to close all windows upon signout?

This solution might not be the exact solution to close all open windows, but it does close all windows upon clicking sign out.
First, you need to create a sign out button on your master page. Then put this code your click event of the button.
Here is the code:
            Session.Clear();
            Response.Redirect("~/LoginPage.aspx");
Second, You need to create a login page. I do not need to put the code for the login page. You can do that.
Third, You need to create javascript that will open each page.
Here is the javascript:
    <script type="text/javascript" language="javascript">
        var winArray = new Array()
        function OpenFirstPage() {
            if (!winArray[0] || winArray[0].closed)
                winArray[0] = window.open("FirstPage.aspx", "FirstPage", "width=800,height=600,toolbar=no, menubar=no, directories=no, resizable=yes, scrollbars=yes");
            else
                winArray[0].focus();
        }
        function OpenSecondPage() {
            if (!winArray[1] || winArray[1].closed)
                winArray[1] = window.open("SecondPage.aspx", "SecondPage", "width=800,height=600,toolbar=no, menubar=no, directories=no, resizable=yes, scrollbars=yes");
            else
                winArray[1].focus();
        }
        function OpenThirdPage() {
            if (!winArray[2] || winArray[2].closed)
                winArray[2] = window.open("ThirdPage.aspx", "ThirdPage", "width=800,height=600,toolbar=no, menubar=no, directories=no, resizable=yes, scrollbars=yes");
            else
                winArray[2].focus();
        }
        function SignOut()
        {
            if (winArray[0] == null)
                OpenFirstPage();
            winArray[0].close();
            if (winArray[1] == null)
                OpenSecondPage();
            winArray[1].close();
            if (winArray[2] == null)
                OpenThirdPage();
            winArray[2].close();
        }
    </script>
Fourth, You need to add attributes to your sign out and button.
Here is the code:
this.lnkUser.Attributes.Add("onclick", "javascript:OpenFirstPage()");
this.lnkTeams.Attributes.Add("onclick", "javascript: OpenSecondPage()");
this.lnkVolunteers.Attributes.Add("onclick", "javascript: OpenThirdPage()");
this.lnkLogout.Attributes.Add("onclick", "javascript:SignOut()");

References used:

No comments:

Post a Comment