title: How to capture the browser window close event on PHP?
body: <p>I found the code below in stackoverflow and it works fine, but how can I capture <code>&lt;input type="button"&gt;</code>? </p>
  
  <p>I tried <code>$('input').on('click')</code>, <code>$('input.button').on('click')</code>, and <code>$('button').on('click')</code> also didn't work. Also is there any method to capture refresh event? Many thanks.</p>
  
  <pre><code>var inFormOrLink;
  $('a').on('click', function() { inFormOrLink = true; });
  $('form').on('submit', function() { inFormOrLink = true; });
  
  $(window).on("beforeunload", function() { 
      return inFormOrLink ? "Do you really want to close?" : null; 
  })
  </code></pre>