简体   繁体   English

如何通过母版页以编程方式关闭ASPX页

[英]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. 就像您收到警告消息的方式一样,对某些浏览器使用window.close是有风险的 ,因为脚本本身并未打开(启动)窗口/选项卡。

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 . 但是,您仍然可以在SO问题中找到有关此问题的一些详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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