title: How can I detect browser tab refresh or close using javascript
body: <p>I have one problem, I have a <code>javascript</code> function which I want to use when the browser is closed, How can I detect that <code>a browser is being closed</code>?  </p>
  
  <p>I have made some research on that I got solution like <code>onunload</code> or <code>beforeunload</code> but both the functions are being executed when I am reloading the page, Is there any solution that I can differentiate reload and browser/tab close.</p>