title: How to determine which control in window.onbeforeunload in javascript caused the event
body: <p>I have set up in javascript:</p>
  
  <pre><code>var    onBeforeUnloadFired = false;
  
  window.onbeforeunload = function (sender, args)
  
  {
     if(window.event){
        if(!onBeforeUnloadFired) {
           onBeforeUnloadFired = true;
           window.event.returnValue = 'You will lose any unsaved changes!'; //IE
        }
     }
     else {
        return 'You will lose any unsaved changes!'; //FX
     }
  
     windows.setTimeout("ResetOnBeforeUnloadFired()", 1000);
  }
  
  function ResetOnBeforeUnloadFired() {
     //Need this variable to prevent IE firing twice.
     onBeforeUnloadFired = false;
  }
  </code></pre>
  
  <p>I'm trying to achieve an edit screen where the user is warned before navigating away. It works fine except I get the pop up for normal post backs of button clicks. I'm hoping to avoid this so I'm figuring if I could determine which button was pressed it would work.</p>
  
  <p>Does anybody know how to determine which button was pressed in the windows.onbeforeunload?</p>
  
  <p>Alternatively anyone know a better approach to what I'm trying to achieve?</p>