Detect web window closing (X)

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...
 
M

Marina Levit [MVP]

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.
 
G

Guest

<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()">
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top