473,320 Members | 2,122 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,320 software developers and data experts.

Is there an event when that triggers when the window is closing??



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!!!
Jul 23 '05 #1
10 9737

"Tom Szabo" <to*@intersoft.net.au> escreveu na mensagem
news:41******@dnews.tpgi.com.au...


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!!!
The Onunload body element an example is given above:
<body OnunLoad="javascript:window.alert('Thanks for visiting our site')">

Jul 23 '05 #2
"Oscar Monteiro" <of**@hotmail.com> wrote in message news:<41***********************@news.telepac.pt>.. .
"Tom Szabo" <to*@intersoft.net.au> escreveu na mensagem
news:41******@dnews.tpgi.com.au...


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!!!
The Onunload body element an example is given above:
<body OnunLoad="javascript:window.alert('Thanks for visiting our site')">


No such thing as an 'Onunload body element' - onunload is an event
handler property (of window). The name of the event you're interested
in is unload, which invokes the [window.]onunload handler.
MSIE/FireFox 0.9+ also support window.onbeforeunload, which allows
more leeway in running script, including cancelling the close
entirely.

Most people who ask about this are interested in discriminating
between an actual attempt to close the window (or navigate to another
site) and a simple change of page within their own site. Since the two
event handlers are called by any of these - the unloading of the
current document is the trigger - all sorts of tortuous methods have
been configured to catch an actual close event, from popping up 'spy'
windows to observe the action, to flagging internal links to trap
their usage to...you name it. My experience with most of these has not
been encouraging. Here's a novel approach from glenngv of
codingforums.com:

<html>
<head>
<title>Detecting Closing of Window in IE</title>
<script language="javascript">
function doUnload()
{
if ((window.event.clientX < 0) && (window.event.clientY < 0))
{
alert("The window is closed...");
}
}
</script>
</head>
<body onunload="doUnload()">
<h3>Detecting Closing of Window in IE</h3>
Do the 3 ways below and see the difference:<br>
1. Try to refresh the page.<br>
2. Try to type any URL in the address bar.<br>
3. Try to close this window by clicking X button of this window.
</body>
</html>

Catches the mouseclick position. IE only, but easily modifiable. What
exactly did you need to do?
Jul 23 '05 #3
RobB" <fe******@hotmail.com> wrote in message
news:ab**************************@posting.google.c om...
"Oscar Monteiro" <of**@hotmail.com> wrote in message news:<41***********************@news.telepac.pt>.. .
"Tom Szabo" <to*@intersoft.net.au> escreveu na mensagem
news:41******@dnews.tpgi.com.au...


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!!!
The Onunload body element an example is given above:
<body OnunLoad="javascript:window.alert('Thanks for visiting our

site')">
No such thing as an 'Onunload body element' - onunload is an event
handler property (of window). The name of the event you're interested
in is unload, which invokes the [window.]onunload handler.
MSIE/FireFox 0.9+ also support window.onbeforeunload, which allows
more leeway in running script, including cancelling the close
entirely.

Most people who ask about this are interested in discriminating
between an actual attempt to close the window (or navigate to another
site) and a simple change of page within their own site. Since the two
event handlers are called by any of these - the unloading of the
current document is the trigger - all sorts of tortuous methods have
been configured to catch an actual close event, from popping up 'spy'
windows to observe the action, to flagging internal links to trap
their usage to...you name it. My experience with most of these has not
been encouraging. Here's a novel approach from glenngv of
codingforums.com:

<html>
<head>
<title>Detecting Closing of Window in IE</title>
<script language="javascript">
function doUnload()
{
if ((window.event.clientX < 0) && (window.event.clientY < 0))
{
alert("The window is closed...");
}
}
</script>
</head>
<body onunload="doUnload()">
<h3>Detecting Closing of Window in IE</h3>
Do the 3 ways below and see the difference:<br>
1. Try to refresh the page.<br>
2. Try to type any URL in the address bar.<br>
3. Try to close this window by clicking X button of this window.
</body>
</html>
Hi Rob,

What I want to do is:

firstly if the child window is closed by the user using the "x" on the top
left corner (that is prematurely considering the actual application) I need
to enable the data controls on the parent window (opener)!!

secondly, if the parent window is closed in the same way, I need to close
the child. -> this is needed because from the child I can disable all the
controls on the parent, but not the "X", so they can close the window...

Thanks for the stuff by the way, I will try soon,

Regards,

Tom


Catches the mouseclick position. IE only, but easily modifiable. What
exactly did you need to do?

Jul 23 '05 #4
Hi Rob,

I have tried, and it doesn't do anything!

No error with the script, just nothing.

Any clues?

TIA,

Tom
"RobB" <fe******@hotmail.com> wrote in message
news:ab**************************@posting.google.c om...
"Oscar Monteiro" <of**@hotmail.com> wrote in message news:<41***********************@news.telepac.pt>.. .
"Tom Szabo" <to*@intersoft.net.au> escreveu na mensagem
news:41******@dnews.tpgi.com.au...


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!!!
The Onunload body element an example is given above:
<body OnunLoad="javascript:window.alert('Thanks for visiting our

site')">
No such thing as an 'Onunload body element' - onunload is an event
handler property (of window). The name of the event you're interested
in is unload, which invokes the [window.]onunload handler.
MSIE/FireFox 0.9+ also support window.onbeforeunload, which allows
more leeway in running script, including cancelling the close
entirely.

Most people who ask about this are interested in discriminating
between an actual attempt to close the window (or navigate to another
site) and a simple change of page within their own site. Since the two
event handlers are called by any of these - the unloading of the
current document is the trigger - all sorts of tortuous methods have
been configured to catch an actual close event, from popping up 'spy'
windows to observe the action, to flagging internal links to trap
their usage to...you name it. My experience with most of these has not
been encouraging. Here's a novel approach from glenngv of
codingforums.com:

<html>
<head>
<title>Detecting Closing of Window in IE</title>
<script language="javascript">
function doUnload()
{
if ((window.event.clientX < 0) && (window.event.clientY < 0))
{
alert("The window is closed...");
}
}
</script>
</head>
<body onunload="doUnload()">
<h3>Detecting Closing of Window in IE</h3>
Do the 3 ways below and see the difference:<br>
1. Try to refresh the page.<br>
2. Try to type any URL in the address bar.<br>
3. Try to close this window by clicking X button of this window.
</body>
</html>

Catches the mouseclick position. IE only, but easily modifiable. What
exactly did you need to do?

Jul 23 '05 #5
RobB wrote:
function doUnload()
{
if ((window.event.clientX < 0) && (window.event.clientY < 0))
{
alert("The window is closed...");
}
}


The alert would also be shown, if a user types in another address and
hits enter (or navigates with keys) while his mouse is above and left
from the browser window.

This might be corrected by adding the screenX and screenY values. If the
resulting value is still negative, the window might be closed. But I
don't know if this must be the case as I couldn't find a reference who
describes the possible values of clientX/clientY for a closed window.

function doUnload() {
var e = window.event;
if (e.clientX+screen.width < 0 && e.clientY+screen.height < 0) {
alert("The window is closed...");
}
}

Daniel
Jul 23 '05 #6
Daniel Kirsch <Iw*****************@gmx.de> wrote in message news:<cn*************@news.t-online.com>...
RobB wrote:
function doUnload()
{
if ((window.event.clientX < 0) && (window.event.clientY < 0))
{
alert("The window is closed...");
}
}
The alert would also be shown, if a user types in another address and
hits enter (or navigates with keys) while his mouse is above and left
from the browser window.

This might be corrected by adding the screenX and screenY values. If the
resulting value is still negative, the window might be closed. But I
don't know if this must be the case as I couldn't find a reference who
describes the possible values of clientX/clientY for a closed window.

function doUnload() {
var e = window.event;
if (e.clientX+screen.width < 0 && e.clientY+screen.height < 0) {
alert("The window is closed...");
}
}

Daniel


Daniel Kirsch wrote:
The alert would also be shown, if a user types in another address and
hits enter (or navigates with keys) while his mouse is above and left
from the browser window.


Interesting - that wasn't my experience: Event.clientX remained
positive except while clicking the 'x', then going wildly negative.
Not to worry: couldn't get this to work in Firefox; both Event.clientY
and Event.pageY remained set to zero regardless. Presumably IE's event
handling in this regard is non-standard (or buggy). Couldn't come up
with a viable solution.
Jul 23 '05 #7
> > > function doUnload()
{
if ((window.event.clientX < 0) && (window.event.clientY < 0))
{
alert("The window is closed...");
}
}


function doUnload() {
var e = window.event;
if (e.clientX+screen.width < 0 && e.clientY+screen.height < 0) {
alert("The window is closed...");
}
}


I don't get this! Does anyone's MSIE pops up anything when they click "x" in
the top left corner???

I can't seem to achieve anything like that!

What is wrong?

TIA

Tom
Jul 23 '05 #8
This comes from Tek-Tips:

http://www.tek-tips.com/viewthread.cfm?qid=924821

By adam0101:
In the onunload event of every page, open the survey at a position off
the screen. In the onload event of every page, close the survey. Then
put a timer in the survey window that repositions itself into view after
about 5 seconds. If another page from your site doesn't get loaded
within 5 seconds to close the survey, it'll display itself.

The tricky part is referencing the popup from the new page. This should
work:
CODE

<body onload="window.open('javascript:window.close()','p opupSurvey')"
onunload="window.open('survey.html','popupSurvey', 'left=-5000')">

In the survey:
CODE

<script>
setTimeout('moveTo(0,0)',5000);
</script>

Adam

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #9
On 26 Nov 2004 09:55:01 GMT, Theo Developer <th**@involveit.nl> wrote:

[snip]
<body onload="window.open('javascript:window.close()','p opupSurvey')"
onunload="window.open('survey.html','popupSurvey', 'left=-5000')">
Which will be blocked by every pop-up blocker in existence.
setTimeout('moveTo(0,0)',5000);


Decent browsers can also ignore that.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #10
Theo Developer wrote:
This comes from Tek-Tips:

http://www.tek-tips.com/viewthread.cfm?qid=924821

By adam0101:
In the onunload event of every page, open the survey at a position off
the screen. In the onload event of every page, close the survey. Then
put a timer in the survey window that repositions itself into view after
about 5 seconds. If another page from your site doesn't get loaded
within 5 seconds to close the survey, it'll display itself.

The tricky part is referencing the popup from the new page. This should
work:
CODE

<body onload="window.open('javascript:window.close()','p opupSurvey')"
onunload="window.open('survey.html','popupSurvey', 'left=-5000')">

In the survey:
CODE

<script>
setTimeout('moveTo(0,0)',5000);
</script>

Adam


Thank goodness nonsense like this doesn't come close to "working" (by any
definition) in my Web browser.

Thank goodness Microsoft has put features in place in Windows XP Service
Pack 2 to stop nonsense like this.

Thank goodness 3rd party vendors like Google and Yahoo and Norton offer
popup blockers that stop nonsense like this.

This advice might have actually worked on Web browsers 2 years ago. Today it
is not only bad functionality advice, it's bad technical advice, because it
simply WILL NOT WORK on a large number of Web browsers in use.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #11

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

Similar topics

18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
2
by: Derek | last post by:
Hello: I want to capture the event when a browser is closing, to give to the user the posibility of close or no this browser. When the browser is closing, this show a confirm window with two...
1
by: Chris Bruce | last post by:
In my application I need a way to distiguish between the following events: 1. When a user closes an MDI child window. 2. When the user closes the MDI parent window which subsequently closes the...
1
by: Chirag Malvi | last post by:
hello all, I am developing the web application using ASP.net and VS.2003 IDE. here is the situation which i want to implement. 1) User is browsing some webform. I want to trap this event....
5
by: Stan Sainte-Rose | last post by:
Hi, Which event is called when the user click on the close window icon (X) ? I want, when he clicks on this icon, to display a message before closing the form. If he replys by No, I don't want to...
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",...
1
by: karthik juneni | last post by:
Hi all, Iam trying to capture windows closing event (i.e) when the user clicks on the "X" button i want to capture that event and want to update some values in the database.I tried two methods...
5
by: jimmy | last post by:
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.