简体   繁体   中英

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..........

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.

Refer this question to prevent browser being closed while you are in middle of an AJAX request.

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