简体   繁体   中英

How to close aspx page programmatically through master page

I'm trying to close the browser tab when user clicks on logout button or session expires but i am not able to close the tab

I have tried using the below solution but its not working.

ScriptManager.RegisterStartupScript(this, this.GetType(), "Close_Window", "window.close();", true);

When using the above code I'm getting console warning in the browser.

"Scripts may close only the windows that were opened by it."

Any help will be appreciated.

I would recommend that the logout action and expiring session will redirect you to a different page of your preference (eg Home page, Login Page, etc). Which you will normally encounter from other websites like social media sites.

Using window.close for certain browsers are considered risky just like how you received the warning message, because the window/tab was not opened (initiated) by the script themselves.

There are probably some workarounds that you can find, but that will still depend per browser, and the hack might differ among them. So I would not suggest this. But still you can find some details about this here in a SO question .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM