473,396 Members | 1,923 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
7 4973
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: hb | last post by:
Hi, Would you please tell me how to detect if the client's browser is closed? I need such event to trigger a database modification. Thank you hb
2
by: NWx | last post by:
Hi, I have the following question: I have an app that uses user login/logout to identify users When user logon, I register logon time in a session variable When user logoff using the logout...
5
by: feng | last post by:
I want to use onunload to capture user's action when he clicks on the "x" button to close the browser. Here is how I do this: <SCRIPT FOR="window" EVENT="onunload"> myScript(); </SCRIPT> ...
3
by: Lord2702 | last post by:
Sat. Oct. 30, 2004 3:25 PM PT I want to detect, if user has close the browser, (after logging to my site), that user has closed the browser. How to achieve it ? I want to know this close action...
8
by: Luke Matuszewski | last post by:
I have read all posts about how to detect that url have changed to new page and trigger the event handler then eg. function aidLogout(evt) { if(evt) { /* maybe via analyse of evt object i can...
2
by: tarun.kataria | last post by:
Hi all, In my ASP.NET application, I am trying to detect in a javascript function, which is triggered by the event onbeforeunload, that if the window is getting closed beacuse its a post back or...
6
by: hemant.singh | last post by:
Hi all, I am trying to get a way by which I'll know exactly when user goes out of my site by clicking on close button in browser, So that w/e user click close button in browser, I can send a...
1
by: nebulus | last post by:
I'm working on a web app that under normal circumstances will be happy with the Session_OnEnd event, but when a user leaves a page by closing the browser by either Alt+F4 or just hitting the "X",...
4
by: nrocha | last post by:
Hello, I've been trying to detect when a user closes a page or navigates away from it. This is part of a solution for locking pages (that is, if a user enters a page, no one else can enter it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.