title: onbeforeunload event with apache wicket
body: <p>I've a problem with the JavaScript event <code>onbeforeunload</code> in Apache Wicket.</p>
  <p>What I want to do: I've a variable which tells me if data has changed. Now I want to open the JavaScript confirm dialog (<code>confirm(&quot;my text&quot;);</code>) to ask if the user is sure that he is losing his changes.
  This dialog should only pop up, if something has changed.</p>
  <p>Does anyone knows how the behavior is working correctly?</p>
  <p>I tried this:</p>
  <pre><code>add(new AjaxEventBehavior(&quot;onbeforeunload&quot;) {
  
      @Override
      protected void onEvent(AjaxRequestTarget target) {
          target.prependJavaScript(&quot;confirm('my dialog');&quot;);
      }
  });
  </code></pre>
  <p>What it does: I get now two dialogs. The first one is a dialog with the text &quot;false&quot; in it. The second one is my real dialog.</p>
  <p>Does anyone has experience with this event?</p>