After running a few code I want to close current tab of browser from codebehind asp.net


After running a few code I want to close current tab of browser from codebehind asp.net



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:


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();
}


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




1 Answer
1



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.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Export result set on Dbeaver to CSV

Opening a url is failing in Swift