473,804 Members | 2,755 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4988
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******** *************@z 34g2000cwc.goog legroups.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******** *************@z 34g2000cwc.goog legroups.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******** *************@z 34g2000cwc.goog legroups.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.goo glegroups.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******** *************@z 34g2000cwc.goog legroups.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 responsibilitie s 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
5243
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
2264
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 link, I also register logoff time and update accordingly the logging history table. However user can simply close the browser without logoff, so his session was closed.
5
1590
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> While myScript() does get called when "x" gets clicked, it is also get called when the user leaves the current page and navigate to another page within our web application.
3
4267
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 on my server-side code. Because if he logout by clicking on Logout/ Sign-Off button it simple to get the message. Although, this is very similar to the first above. Also, if user takes any action on client-side or browser side how will I detect...
8
17384
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 detect the close of the browser window */ } if(window.event) { /* maybe via analyse of window.event object i can detect the close of the browser window */
2
1574
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 if the user has clicked the X button of the browser. Is there a way in javascript to know that a postback is about to happen i.e. the user has clicked a button (asp.net control). thanks
6
3948
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 signal to server. This seems to be achievable with body unload events, but it is little too much, as even if user navigate within my site, this event will be generated, this can be avoided by handling onclick of each link, so that I'll know exactly...
1
33186
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", I'll need to kill the session. Now, with the onbeforeunload event, I can handle this quite easily in IE, but in FireFox, it's another matter. For one thing, FireFox seems to empty out its event object on a page unload, so it's very hard to track...
4
7920
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 while he doesn't leave). I'm using the window.onunload event to trigger the unlocking of a page, but I don't want the page to be unlocked when a postback or a refresh occurs...I only want it when the user goes to another page or closes the...
0
9705
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9576
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10074
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2988
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.