title: Can't make sens out of javascript event and functions
body: <p>Here is the code that works as-is, a classic onBeforeUnLoad event, in the <code>&lt;script type="text/jscript"&gt;</code> tag of my ASP page :</p>
  
  <pre><code>window.onbeforeunload = function (e) {
          a = 1;
          e = e || window.event;
          e.preventDefault = true;
          e.cancelBubble = true;
          e.returnValue = "do you wish to save?";
  }
  </code></pre>
  
  <p>Now, two issues i'm experiencing when wanting to do something more complex :</p>
  
  <ol>
  <li><p>I want this to appear only once at all cost :</p>
  
  <pre><code>var a = 0;
  
  window.onbeforeunload = function (e) {
  
      if (a == 0) {
          a = 1;
          e = e || window.event;
          e.preventDefault = true;
          e.cancelBubble = true;
          e.returnValue = "Wish to save?";
      }
  }
  
   //Does not work...
  </code></pre></li>
  <li><p>I want it to be able to run this other function that <strong>works</strong> when not combined with the first :</p>
  
  <pre><code>comfirmExit = function(){
      if (confirm("Wish to save?") == true) {
      document.getElementById('&lt;%= btnEnregistrer.ClientID %&gt;').click();
      }
   }
   // works, but not when combine to the first function
  </code></pre></li>
  </ol>
  
  <p>I tried to put this all together... I want the unload event to make my confirm box function run :</p>
  
  <pre><code>    window.onbeforeunload = function (e) {
  
          if (a == 0) {
              a = 1;
          comfirmExit = function(){
          if (confirm("Wish to save?") == true) {
          document.getElementById('&lt;%= btnEnregistrer.ClientID %&gt;').click();
              }
          }
      }
  </code></pre>
  
  <p>And now I realize I'm far from being an expert of javascript...</p>