-2

Is there any way to detect if user closing open window from close tab of browser in javascript except onbeforeunload function this occurs on page refresh, form submission, button click etc so this is not my solution.

1 Answers1

0

You can track the mousemovement and if the mouse leaves the screen a user may leave your page. You have no 100% guarantee to detect if a user is closing a page.

Code Spirit
  • 3,992
  • 4
  • 23
  • 34
  • But user may scroll their mouse on screen while access the account.. i have to make user logout if they close the browser. – Rahul TrlIt Jul 16 '19 at 11:27
  • If a user scrolls, the mouse is not leaving the screen (browser window). But also you should not do a logout like this because as I said you cant be 100% sure if a user is closing his window. Ive done an exit intent popup using the technique I mentioned and was surprised myself how well it works. – Code Spirit Jul 16 '19 at 11:29
  • spirits i tried the way you explained above but not getting on, could you please give me a hint link if any. Thanks – Rahul TrlIt Jul 16 '19 at 12:04
  • The keyword here is **Exit Intent (Popup)** – Code Spirit Jul 16 '19 at 12:06