Html: How to catch browser close
This is one of the common questions in web development. How can we catch the event when user presses X in the top-right corner of the browser window and do some staff. Pay attention to the difference between this and the body "onUnload" event, which happens on each postback. The following example shows the way how to catch X - when user closes browser.
< html > < title >< /title > < head > < script language="Javascript" > var f = 0; function myfun(n) { alert(n); if(n == 0) { opener.document.getElementById("b").value = "aaaa"; opener.document.forms(0).submit(); } } < /script > < /head > < body onunload = "myfun(0);"> < form name = "x" > < input type="text" name="f" value="" > < input type="button" value="1" onClick="myfun(1);" > < input type="button" value="2" onClick="myfun(2);" > < input type="button" value="3" onClick="myfun(3);" > < /form > < /body > < /html >
Wednesday, September 15, 2004 3:19 AM