0

How can I distinguish browser close and reload/refresh/f5 though jQuery/JS? I want to update database (via ajax) when close browser/tab and keep all as it is when reload.

What I am doing now is same action running when reload or close. But after reload again run a restore function (via ajax) to set back in previous state.

Tried How can I detect browser tab refresh or close using javascript not worked. Any Idea? cron job is not real time. I need real time action

Professionals help please how you handle this issue.

Community
  • 1
  • 1
Rejoanul Alam
  • 5,435
  • 3
  • 39
  • 68
  • the browser close can come form a lost of connection. then I see 2 possibility, first you save everything every 1 minute e.g.. secondly you save only what is changed by the user. – mmm Aug 30 '15 at 07:07
  • to the best of my knowledge, this is not possible with JS - `onunload()` and `onbeforeunload()` functions are called in any page change event, regardless of where it came from... and they are the only one we can use to detect this – Zathrus Writer Aug 30 '15 at 07:12
  • Cron job isn't realtime, but maybe you could run some cleanup procedure in the beginning of every php script related to that database stuff? – Serge Seredenko Aug 30 '15 at 07:53
  • i think it's not possible – Varun Kumar May 11 '16 at 10:33

0 Answers0