1

If I start writing post in Facebook and then either close or refresh page, Facebook somehow recognizes each of these actions (Reload site vs Leave site).

enter image description here

In javascript there's onbeforeunload event that gets called when webpage is about to unload, but how does Facebook manage to recognize if page unloads due to browser close or browser refresh function? Event doesn't contain that information afaik.

window.addEventListener('beforeunload', function(e) {
    // this is browser refresh or close?
});
mgs
  • 2,621
  • 2
  • 19
  • 14
  • 1
    possible duplicate of: https://stackoverflow.com/questions/568977/identifying-between-refresh-and-close-browser-actions – zedling May 22 '18 at 14:18
  • 1
    also this might be the solution you are looking for: https://stackoverflow.com/questions/5004978/check-if-page-gets-reloaded-or-refreshed-in-javascript – zedling May 22 '18 at 14:20
  • 3
    This has nothing to do with Facebook. It is how the `beforeunload` event works. The browser knows the difference, but there is no way for you to access that event difference. You'd need a different approach. – Scott Marcus May 22 '18 at 14:22

0 Answers0