Detect web window closing (X)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

is there a simple way to detect a web window closing when the user hit the X
of the browser ? I want to display a message to the user when he goes out of
my web page.
I try to detect it by using the event window.unbeforeunload but this event
is fire when the page is postback...
 
That event is the only way. You have to keep track in your page whether or
not the user just did something that would cause a postback and only show
the message if the user did not just do something to interact with your
page.
 
<head runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
// <!CDATA[

function window_onunload() {
alert("Window Closing");

return;
}

// ]]>
</script>
</head>
<body onunload="return window_onunload()">
 
Back
Top