简体   繁体   English

如何在浏览器关闭时执行数据库操作?

[英]How to perform database operations on browser close?

I am developing online chatting in my website. 我正在网站上开发在线聊天。 Some users close the browser when they are in online. 某些用户在线时会关闭浏览器。 I want to done some database operations when user closes the browser 我想在用户关闭浏览器时执行一些数据库操作

I use this one 我用这个

 window.onbeforeunload = function (event) {
            event = event || window.event;
            if ((event.clientX < 0) || (event.clientY < 0) || event.clientY < -80) { 
}

it does not work in non IE browsers.......... 它不适用于非IE浏览器..........

Can any one help me 谁能帮我

Refer this question on how to capture the browser close event. 有关如何捕获浏览器关闭事件,请参考问题。

Now what you can do is do an AJAX call in the event to call a Web Service, which in-turn does update your database accordingly. 现在,您可以做的是在事件中进行AJAX调用以调用Web Service,这反过来又会相应地更新数据库。

Refer this question to prevent browser being closed while you are in middle of an AJAX request. 请参考问题,以防止在您遇到AJAX请求时关闭浏览器。

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

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