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.
Asked
Active
Viewed 46 times
-2
-
Why php and wordpress? – Vega Jul 16 '19 at 14:41
-
@Vega my web application is in php and wordpress – Rahul TrlIt Jul 17 '19 at 06:43
-
But these tags are irrelevant to the question content here. Also have you seen https://stackoverflow.com/q/3888902/5468463? – Vega Jul 17 '19 at 06:57
1 Answers
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
-