473,748 Members | 3,823 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Captue window.close() event

Hi all,
I want to capture the event when the browser's close button is
clicked
in an html page.
I tried using the event.ClientX and event.ClientY property in the
body unload event, and this helps to recognise whether the close
button is clicked( also differentiates whethet refresh was clicked).
The problem arises whenever i try to close the window by resizing it
or by right clicking at the bottom of the page and then closing it.
Can anybody tell how to capture the window.close() event??

Apr 2 '07 #1
5 34367
jimmy said the following on 4/2/2007 8:05 AM:
Hi all,
I want to capture the event when the browser's close button is
clicked in an html page.
That depends on what you mean by "in an html page". If you are referring
to the X on the upper right corner of a PC Based browser window, then
give up now because you will ultimately fail. Searching the archives for
capturing when a window closes will show that it is a futile exercise.
I tried using the event.ClientX and event.ClientY property in the
body unload event, and this helps to recognise whether the close
button is clicked( also differentiates whethet refresh was clicked).
I find that a difficult claim to believe. Especially considering that
the X that is required to close a page in IE7 - in tab mode - can be
anywhere other than the top right corner of the browser window.
The problem arises whenever i try to close the window by resizing it
or by right clicking at the bottom of the page and then closing it.
Close a window by resizing it? How do you do that?
Can anybody tell how to capture the window.close() event??
You can't. Besides, why does it matter whether I close my browser or
not? I can close your page without closing my browser.

If you have some reason to need to know when the page is closed so you
can clean up some code on the server then the browser isn't the place to
do that, the server is with Sessions.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 2 '07 #2
jimmy wrote :
Hi all,
I want to capture the event when the browser's close button is
clicked
in an html page.
I tried using the event.ClientX and event.ClientY property in the
body unload event, and this helps to recognise whether the close
button is clicked( also differentiates whethet refresh was clicked).
The problem arises whenever i try to close the window by resizing it
How do you actually close a window by resizing it?
or by right clicking at the bottom of the page and then closing it.
What's your page url?
Can anybody tell how to capture the window.close() event??
Why do you want to "capture" the close event? What exactly are you
trying to do? Can you provide explanations, description regarding your
webpage goals, requirements, purposes? What close event do you really
want to "capture": the webpage being unloaded or the window being closed?
In which way dealing with the closing of the window or unloading of a
webpage is actually contributing to the content for the users or
contributing to the experience of the users?

Gérard
--
Using Web Standards in your Web Pages (Updated Dec. 2006)
http://developer.mozilla.org/en/docs...your_Web_Pages
Apr 4 '07 #3
How do you actually close a window by resizing it?
I meant after resizing it...
Why do you want to "capture" the close event? What exactly are you
trying to do? Can you provide explanations, description regarding your
webpage goals, requirements, purposes? What close event do you really
want to "capture": the webpage being unloaded or the window being closed?
In which way dealing with the closing of the window or unloading of a
webpage is actually contributing to the content for the users or
contributing to the experience of the users?
Problem is that whenver te user changes the data on the screen and
leaves it without saving the data, I prompt user to save the data by
calling a function on the body onunload event.

So in the body unload event i call a function which does the following
thing:-
*************** *************** *************** *******
if (event.clientY < 0 && event.clientX 500)
{
//don't ask the user to save the data
}
*************** *************** *************** ******
Event here refers to the click and
event.clientY < 0 ensures that the button wasn't clicked in the
body and event.clientX >500 ensures that the user is not prompted to
save
when the refresh button is clicked, bcoz the page would unload in
that
event also.
I know that event.clientX >500 won't work when the screen size or the
browser's size is small...that is one of the problems i m facing
besides the user closing the window using Alt+F4 or by right clicking
at the bottom and then closing it..

Apr 4 '07 #4

I think there is a way to do it. Just open your gmail account and
compose a new message. If you navigate away from the page or close
the browser there is a popup to save changes.

I think this is excatly what jimmy was looking for. And quite frankly
I'm looking for the same thing. I'm going to be looking through the
google code to see if I can figure out how they interrupt/catch the
close event.

If anyone has any other comments they are quite welcome.

Thanks!

Apr 12 '07 #5
terriblecow said the following on 4/12/2007 3:55 PM:
I think there is a way to do it.
A way to do what?
Just open your gmail account and compose a new message.
What gmail account?
If you navigate away from the page or close
the browser there is a popup to save changes.
onbeforeunload, and as I have already said, it is unreliable at best.
I think this is excatly what jimmy was looking for. And quite frankly
I'm looking for the same thing. I'm going to be looking through the
google code to see if I can figure out how they interrupt/catch the
close event.

If anyone has any other comments they are quite welcome.
I have one. Try quoting what you are replying to.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 12 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1820
by: DaveF | last post by:
Is it possible to capture the enter button and run a javascript function? -- David
4
10285
by: KS | last post by:
Is it possible to write a javascript that makes a popup window when someone click on buttons/href on my page and close itself when the new page is about to get loaded? I want to prevent the user from clicking anything else on my page while the request is getting a new page. The popup window must lock the focus. I use frames i can not just disable all the buttons an href in different frames.
10
9801
by: Tom Szabo | last post by:
Is there an event when that triggers when the window is closing.... I am talking about when the user clicks on the cross on the right top corner of the window!!!
19
31067
by: Darren | last post by:
I have a page that opens a popup window and within the window, some databse info is submitted and the window closes. It then refreshes the original window using window.opener.location.reload(). The problem is that after the reload, it brings you right to the top of the page. When I click 'refresh" on the original page, it brings me back to the original viewing position. Is there a way to duplicate this in from the popup window. Also,...
1
11581
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at http://weblogs.asp.net/asmith/archive/2003/09/15/27684.aspx but it was far more complex then I needed. (I got lost trying to figure it all out). Therefore, here goes my simple "web dialog box with parent event handler fireing" solution. ...
1
2690
by: RJN | last post by:
Hi I have a pop-up window which has a task menu on its left which are nothing but links to different screens. This window also has a close button. On click of close button I do some server side operation and the window closes itself. Now the user can close the window by clicking on X(Top right corner) or by pressing Alt+F4 window. I want to atleast alert the user when he does these 2 things to inform he has not clicked on the close...
2
3021
by: Tom | last post by:
How is the best way to avoid validation when closing a window? For instance, I have a Windows Forms window which has a validation event for a text box. However, if one enters invalid data in then and then attempts to close the window (either via my custom 'Close' box or by clicking the close 'X' in the upper right window corner), the validation event still triggers and it tells the user that they have invalid data. Which of course means...
5
3094
by: lindanr | last post by:
In ASP.NET 2005 I have an onblur="window.close()" javascript event in the <body> tag. When I click on the window's scrollbar, the window closes. The same code works fine in ASP.NET 2003. Any ideas?
4
6098
by: bsm | last post by:
Hi, I have googled for my issue in this group. This question was asked many times and many solution was given. But I want clear cut solution for the issue. The issue is: I tried to capture the browse close event by using Body onunload=fn1() statement and it is working fine.
0
8991
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
9247
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...
0
8242
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
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
6074
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
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3312
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
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.