In a browser extension, how do I click a specific button of an alert?
<p>So...</p>

<p>I need to click <code>[Stay on this page]</code> automatically in such a prompt:</p>

<blockquote>
  <p>Confirm navigation: [Leave this page] [Stay on this page]</p>
</blockquote>

<p>The code that invokes this is </p>

<pre><code>$(window).bind('beforeunload', function() {
  return 'Leave page?';
  //Click prompt code goes here.
  $(window).unbind();
});
</code></pre>

<p>If I take away <code>return 'Leave page?';</code> 
then the iframed page overrides the top frame and the user is struck with an unknown site, maybe there's another way to do this?</p>
