control window.onbeforeunload event
<p>From out of curiosity can i Control window.onbeforeunload event like check if the user decided to leave the page or stay in it and can I raise an alert or some function based on his decision if yes please tell me </p>

<pre><code>&lt;script type="text/javascript"&gt;
$(window).bind("beforeunload",function(){
if(//stay on page)
alert("i want to stay on the page");
else //leave page
 alert("i want to leave the page");
});
&lt;/script&gt;
</code></pre>

<p>I understand that window.onbeforeunload is an event that give the user a message to tell him that maybe you forget to do something before you leave but this quest is just out of curiosity and thank you </p>
