我想在用户单击以关闭浏览器而不注销时通知我的用户 [英] I want to notify my user when he clicks to close browser without logout

查看:100
本文介绍了我想在用户单击以关闭浏览器而不注销时通知我的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要通知用户关闭浏览器而不注销时显示一个弹出窗口.

I want to notify the user to show a popup window when he closes the browser without loggingout.

推荐答案

您需要获取关闭 [
You need to get the Window.Closing Event[^] which occurs directly after Close [^]is called, and can be handled to cancel window closure.
public event CancelEventHandler Closing



在这种情况下,您可以检查用户是否注销,如果没有注销,则取消窗口关闭和关闭.防止您的窗口关闭.

这是
如何在ASP.Net(C#)中检测浏览器关闭事件的参考 [ ^ ],您可能会从中获得一些帮助.



On this event you can check whether user is logged out or not, if not then cancel the window closure & prevent your window from closing.

Here is reference for How to detect the browser close event in ASP.Net (C#)[^] you may get some help from it.


使用onbeforeunload事件

Use onbeforeunload event

<script type="text/javascript"> 
window.onbeforeunload = function (evt) { 
  var message = 'Are you sure you want to leave?'; 
  if (typeof evt == 'undefined') { 
    evt = window.event; 
  } 
  if (evt) { 
    evt.returnValue = message; 
  } 
  return message; 
} 
</script> 



另请参考以下链接:
http://forums.asp.net/p/1153888/1891072.aspx [ ^ ]
通过单击[X]按钮来检测浏览器关闭 [ ^ ]
浏览器的窗口关闭事件 [ http://mistonline.in/wp/detect-browser -close-event-and-alert-some-messages-using-javascript/ [



Also refer below link:
http://forums.asp.net/p/1153888/1891072.aspx[^]
Detect browser closing through clicks on the [X] button[^]
Window Close Event of Browser[^]
http://mistonline.in/wp/detect-browser-close-event-and-alert-some-messages-using-javascript/[^]


这篇关于我想在用户单击以关闭浏览器而不注销时通知我的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆