How can I run javascript when user close the browser. I tried to use 'onunload', but it calls every time I press F5/refresh button? Thanks
Asked
Active
Viewed 1,791 times
1 Answers
2
As far as the Javascript on the page is concerned, there's no difference between closing the browser, navigating to another page or refreshing the same page.

nickf
- 537,072
- 198
- 649
- 721
-
1nickf is right though - attaching an event to onbeforeunload or onunload will trigger on closing, refreshing or navigating away. – John Strickler Jun 27 '11 at 14:21
-
1My guess is that even though your answer is correct, it disappointed the OP greatly. – John Strickler Jun 28 '11 at 15:09