JavaScript to check when the browser window is close

Does anyone know any way that I can use javascript to check when the browser window is close and pop-up a confirmation dailog to ask whether the user is confirm to exit the browser or change his mind to stay?
Here is the answer to above questions.

<script language="javascript">
window.onbeforeunload = function ()
{
	var disp_txt = "";

	disp_txt+= "WAIT! READ THIS MESSAGE.\n\n";
	disp_txt+= "Yepie, you got the answer here.\n\n";

	location.assign("http://blog.kapilsakhare.in");
	return disp_txt;
}
</script>


Leave a Reply

You must be logged in to post a comment.