title: Notify user on browser close only
body: <p>I am trying to implement notifying when the user closes or reloades the page.Crrently i am using the following code</p>
  
  <pre><code>function unloadPage(){
      return "Your changes will not be saved.";
  }
  window.onbeforeclose = unloadPage;
  </code></pre>
  
  <p>This works fine.But the problem is this happens whenever a navigation takes place.That is either a page refresh or a form submission or a hyperlink click or whatever navigation takes place..I just want to work this code only for browser refreshing and closing.I knew about setting a flag and checking it.
  But i have to integrate this in a big application.So it will be difficult to add the code in every page.So is there an easy way.
  Is there a way to catch the refresh or browser cosing so that  can use it.</p>