473,395 Members | 1,742 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,395 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 9745

"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: 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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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.