By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,678 Members | 1,329 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,678 IT Pros & Developers. It's quick & easy.

How can I detect a user has clicked the X to close the Browser Window

P: n/a
Hi All,

Is there any way to detect that the user is trying to Xout the browser
window instead of hitting a button. Because in my application I want to
make it sure that they dont do it either knowingly or accidently.
Its an ASP.NET application with C#.

Thanks
Tarun

Mar 31 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
You may be able to take advantage of the client side OnClose event.
Here's more info:
http://www.mozilla.org/docs/dom/domr...dow_ref56.html

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
<ta***********@gmail.com> wrote in message
news:11*********************@z34g2000cwc.googlegro ups.com...
Hi All,

Is there any way to detect that the user is trying to Xout the browser
window instead of hitting a button. Because in my application I want to
make it sure that they dont do it either knowingly or accidently.
Its an ASP.NET application with C#.

Thanks
Tarun

Mar 31 '06 #2

P: n/a
Thanks for your reply. But I tried it and it doesnt work. actually
there is no onclose event in javascript for window object. I also found
this discussion on a forum

http://www.thescripts.com/forum/thread431659.html

but they also dont have a concrete answer to how to implement it.

if anybody encountered the same problem please let me know.

thanks
Steve C. Orr [MVP, MCSD] wrote:
You may be able to take advantage of the client side OnClose event.
Here's more info:
http://www.mozilla.org/docs/dom/domr...dow_ref56.html

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
<ta***********@gmail.com> wrote in message
news:11*********************@z34g2000cwc.googlegro ups.com...
Hi All,

Is there any way to detect that the user is trying to Xout the browser
window instead of hitting a button. Because in my application I want to
make it sure that they dont do it either knowingly or accidently.
Its an ASP.NET application with C#.

Thanks
Tarun


Mar 31 '06 #3

P: n/a
I don't think you can stop someone closing their browser window, you can only
do something such as pop up a new window if they do. Think how iritating it
would be if websites could stop you closing the browser.

"ta***********@gmail.com" wrote:
Hi All,

Is there any way to detect that the user is trying to Xout the browser
window instead of hitting a button. Because in my application I want to
make it sure that they dont do it either knowingly or accidently.
Its an ASP.NET application with C#.

Thanks
Tarun

Mar 31 '06 #4

P: n/a
Tarun see this sample at:-
It should guide you
http://www.4guysfromrolla.com/demos/...nloadDemo1.htm
Patrick

<ta***********@gmail.com> wrote in message
news:11*********************@z34g2000cwc.googlegro ups.com...
Hi All,

Is there any way to detect that the user is trying to Xout the browser
window instead of hitting a button. Because in my application I want to
make it sure that they dont do it either knowingly or accidently.
Its an ASP.NET application with C#.

Thanks
Tarun

Mar 31 '06 #5

P: n/a
The truth is, there is no way to do this. The Mozilla object model supports
it, but Internet Explorer does not. It only supports "onbeforeunload" which
fires any time the *document* is unloading from the window, including, but
not limited to, when the window is closed. There is no existing standard for
it, so as to whether there ever *will* be an "onclose" event in all
browsers, your guess is as good as mine, and I'm not guessing.

A browser will never behave the same way as a desktop application. You can't
prevent people from either accidentally or intentionally closing their
browser. In any application, it is impossible to prevent people from doing
absolutely anything wrong, and closing an application isn't wrong. At a
certain point, you have to expect the user to assume a certain amount of
responsibility for what they do. And that's a good thing.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

<ta***********@gmail.com> wrote in message
news:11**********************@t31g2000cwb.googlegr oups.com...
Thanks for your reply. But I tried it and it doesnt work. actually
there is no onclose event in javascript for window object. I also found
this discussion on a forum

http://www.thescripts.com/forum/thread431659.html

but they also dont have a concrete answer to how to implement it.

if anybody encountered the same problem please let me know.

thanks
Steve C. Orr [MVP, MCSD] wrote:
You may be able to take advantage of the client side OnClose event.
Here's more info:
http://www.mozilla.org/docs/dom/domr...dow_ref56.html

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
<ta***********@gmail.com> wrote in message
news:11*********************@z34g2000cwc.googlegro ups.com...
> Hi All,
>
> Is there any way to detect that the user is trying to Xout the browser
> window instead of hitting a button. Because in my application I want to
> make it sure that they dont do it either knowingly or accidently.
> Its an ASP.NET application with C#.
>
> Thanks
> Tarun
>

Mar 31 '06 #6

P: n/a
Thanks for so many responses. I am completely agree with Mr.Spencer
that user should take some responsibilities that how to use the
application. But ask me, I work in a mortagage company and the loan
agents cant even follow that if some field is required (I show the
error message near the control that its required by using validation
controls) then they wont be able to submit it. They come to me and saqy
"its not working".After so many instructions and training sessions I
put the validation summary which pops open in front of there eyes and
now they can understand it. I think we should design our applications
by assuming that its gonna be used by monkeys and you cant control
their behaviour.
As far as the solution to the problem is concerned what Patrick has
told me it works but now the problem is that I have some controls on
that form for which AutoPostBack property is true. So even if the user
selects a radio button from radio button list, the page post backs, and
before that it gives you the same confirmation box. I only want that
confirmation box when the user is clicking the X button.

Mar 31 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.