简体   繁体   English

如何在Web应用程序的浏览器上禁用按钮关闭?

[英]How To Disable Button Close On Browser For Web Application?

I have Application Web based ASP.Net Framework 1.0, for security i want Button Close (X) in browser(ie,firefox,opera etc.) is disable and reason anything make browser exit, user only can exit browser with my menu logoff. 我有基于应用程序Web的ASP.Net Framework 1.0, 为了安全我想在浏览器中关闭Button(X)(即firefox,opera等)被禁用并且因为浏览器退出原因,用户只能通过我的菜单注销退出浏览器。

Please help me 请帮我

Thanks in Advance 提前致谢

Regards, Yusan Susandi. 此致,Yusan Susandi。

You can't do this, sorry. 对不起,你不能这样做。 You'll have to implement a server-side timeout mechanism, etc. You can make it a fairly short timeout and use an ajax request behind-the-scenes to keep the session alive, but you cannot prevent the browser from closing. 您必须实现服务器端超时机制等。您可以使其超时相当短,并在幕后使用ajax请求以保持会话处于活动状态,但您无法阻止浏览器关闭。

And really, you don't want to rely on doing so anyway, because browsers can crash rather than close, computers can get unplugged rather than shut down properly, etc., all without your server being notified. 实际上,你不想依赖这样做,因为浏览器可能会崩溃而不是关闭,计算机可能会被拔掉而不是正常关闭等等,所有这些都不会通知您的服务器。 So you have to handle the fact that people can abruptly disappear anyway . 所以你必须处理这样一个事实,即无论如何人们都会突然消失。

For the normal use case, you can encourage your users to use the Logout link instead using JavaScript: 对于正常用例,您可以鼓励用户使用Logout链接而不是使用JavaScript:

<script>
window.onbeforeunload = function() {
    if (loggedIn) {
        return "Please cancel and use the Logout link instead";
    }
};
</script>

...which will nag them on most (but not all) browsers, but you can't make them do it. ...它会在大多数(但不是全部)浏览器上唠叨,但你不能它们这样做。

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

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