title: Avoid popup on refresh. show only when user close browser window
body: <p>I want to show popup only when user close the browser window. But, In the following code. It showing popup when I refresh the page.</p>
  
  <p><strong>My Code</strong></p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $(document).ready(function()
      {
          var key = true;
          $(window).bind('beforeunload', function(e){
              if(key)
               return confirm("Do you really want to close? This will log you out of your profile."); 
           e.preventDefault()
          }); 
          $(document).on("click","a",function() {
            key=false; 
          });    
      });
  &lt;/script&gt;
  </code></pre>