0

Basically,What I want is when user click on the logout button, I want to close current browser tab from codebehind. code that I have tried

protected void LoginStatus1_LoggedOut(object sender, EventArgs e)
{
     FormsAuthentication.SignOut();
     Response.RedirectToRoutePermanent("logout"); 
}

Now let me show you that logout page which matched with route value:

logout.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["_underid"].Value != "15")
{
ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "alert01", "closeTab();", false);
}
Request.Cookies.Clear();
Response.Cookies.Clear();
Session.Abandon();
}

logout.aspx

function closeTab() {
debugger;
//window.close();
window.open(location, '_self').close();    

} But still not able to close browser window/current tab.. Its showing this, enter image description here

Nody
  • 85
  • 9

1 Answers1

0

The error message explain well.

It is actually due to the security issue in https://www.w3.org/TR/html51/browsers.html#dom-window-close

The close() method on Window objects should, if all the following conditions are met, close the browsing context A:

The corresponding browsing context A is script-closable.

The responsible browsing context specified by the incumbent settings object is familiar with the browsing context A.

The responsible browsing context specified by the incumbent settings object is allowed to navigate the browsing context A.

A browsing context is script-closable if it is an auxiliary browsing context that was created by a script (as opposed to by an action of the user), or if it is a top-level browsing context whose session history contains only one Document.

As a consequence, you can only close a page that is opened by the script.

Community
  • 1
  • 1
user3003238
  • 1,517
  • 10
  • 17