title: Javascript onload and onunload
body: <p>Consider the following HTML snippet containing some javascript utilizing <code>prompt</code> and <code>unload</code>. The <code>prompt()</code> method works fine but I want alerting something like <strong>Goodbye, user</strong> when reloading or leaving the page. Any help is greatly appreciated.</p>
  
  <pre><code>&lt;body onload="promptName()" &gt;
  
  
          &lt;script type="text/javascript"&gt;
          function promptName()
          {
              var userName = prompt("What's your name ?", "")
              return userName;
          }
  
          function goodBye()
          {
              alert("Goodbye, " + promptName() + "!");
          }
  
          window.onunload = goodBye();
  
          &lt;/script&gt;
  
    &lt;/body&gt;
  </code></pre>