-2

I own a Website. And I need a script that executes a MySQL query whenever the client tries to close the current tab/window/browser. The client has its own table on my MySQL database, so I need to delete that table when the client exits my site.

Any help on that?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Jerome
  • 115
  • 2
  • 2
  • 8
  • See [Browser window close event](http://stackoverflow.com/questions/1631959/browser-window-close-event) – Justin Jun 25 '13 at 14:30

1 Answers1

0

Use the window.onunload event.

https://developer.mozilla.org/en-US/docs/Web/API/window.onunload

You should be able to make an ajax call to run the query that you want to run from there.

AndrewK
  • 717
  • 5
  • 11
  • I'm sorry man, i really tried, i really tried to understand that window.onunload thing, but is not working. I'm really frustrated. I'll wait for another answer. Thank You for your help, BTW – Jerome May 27 '13 at 05:04
  • Are you using jQuery? – AndrewK May 29 '13 at 03:39
  • I wasn't. Luckily i didn't need this anymore, found another way to do what i wanted to do. Anyway, thank You for your help bro. – Jerome May 29 '13 at 14:57