0

I've got the following issue:

I'd like to execute an AJAX request through JS, which would call the mysql query and clear some data in database(UPDATE and stuff,whatever) when user is leaving my web page.

Does anyone have any ideas how to do such thing?

I mean I'm only missing one piece of the whole process: JavaScript function(event or something).

CoderDojo
  • 65
  • 1
  • 12
travisspears
  • 59
  • 1
  • 1
  • 7
  • Take a look at the `onbeforeunload` event - https://developer.mozilla.org/en-US/docs/Web/API/Window.onbeforeunload – Lix May 01 '14 at 15:09
  • possible duplicate of [Best way to detect when a user leaves a web page?](http://stackoverflow.com/questions/147636/best-way-to-detect-when-a-user-leaves-a-web-page) – Lix May 01 '14 at 15:10
  • Sorry guys!I saw that topic but I thought it was only about asking if user is sure to leave, which was not what I was lookin' for. Anyone who see this and is powerful enough here, should go ahead and remove the whole topic or something. Thanks btw(it works). – travisspears May 01 '14 at 15:17
  • I tried to determine when a user left a page a while back, and I don't believe you can guarantee the code will always get triggered. Certainly with Chrome I believe there is a problem, we had users losing data keyed into Ckeditor that was lost when Chrome decided to do a background update and reload the browser. – Tony Payne May 01 '14 at 15:24

0 Answers0