| | |
Detect browser window closing event in Firefox -
Please support our JavaScript / DHTML / AJAX advertiser: 50% Off 6 Months Web Hosting from 1&1. The World's #1 Host!
Thread Solved |
Hi,
I want to execute some java script code when I close the browser. The following code is executing in I.E. But I want to execute in Firefox and Netscape.
<html>
<head>
<script language="JavaScript">
function doUnload(evt)
{
var e = (window.event) ? window.event : evt;
if (e.clientX < 0 && e.clientY < 0){
{
alert("window closing....");
}
}
</script>
</head>
<body onunload="doUnload(event)">
</body>
</html>
In firefox clientX and clientY are getting as "undefined"....
Can any One Please help me.
Thanks in advance
Deepthi
I want to execute some java script code when I close the browser. The following code is executing in I.E. But I want to execute in Firefox and Netscape.
<html>
<head>
<script language="JavaScript">
function doUnload(evt)
{
var e = (window.event) ? window.event : evt;
if (e.clientX < 0 && e.clientY < 0){
{
alert("window closing....");
}
}
</script>
</head>
<body onunload="doUnload(event)">
</body>
</html>
In firefox clientX and clientY are getting as "undefined"....
Can any One Please help me.
Thanks in advance
Deepthi
This a a cross browser compatible script for finding out the mouse coordinates using Javascript. Referred from this site.
javascript Syntax (Toggle Plain Text)
function doSomething(e) { var posx = 0; var posy = 0; if (!e) var e = window.event; if (e.pageX || e.pageY) { posx = e.pageX; posy = e.pageY; } else if (e.clientX || e.clientY) { posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop; } alert(posx + ", " + posy); }
Last edited by ~s.o.s~; Jul 2nd, 2007 at 4:04 am.
I don't accept change; I don't deserve to live.
Sacrifice is a painful, pure and beautiful thing.
Dammit, Jones, What the Hell Are Knoll Pointers?!
Sacrifice is a painful, pure and beautiful thing.
Dammit, Jones, What the Hell Are Knoll Pointers?!
The coordinates are working fine in my case. There must be some error on your part. Post the code if it still doesn't work.
As for executing a function when the window closes, you can use the onunload callback function.
Here is an example:
As for executing a function when the window closes, you can use the onunload callback function.
Here is an example:
html Syntax (Toggle Plain Text)
<html> <head> <script> function doSomething(e) { var posx = 0; var posy = 0; if (!e) var e = window.event; if (e.pageX || e.pageY) { posx = e.pageX; posy = e.pageY; } else if (e.clientX || e.clientY) { posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop; } alert(posx + ", " + posy); } function confirmMe() { alert("Thank you for visiting us!!"); } </script> </head> <body onunload="confirmMe();"> <div onclick="doSomething(event);">Hello there</div> </body> </html>
I don't accept change; I don't deserve to live.
Sacrifice is a painful, pure and beautiful thing.
Dammit, Jones, What the Hell Are Knoll Pointers?!
Sacrifice is a painful, pure and beautiful thing.
Dammit, Jones, What the Hell Are Knoll Pointers?!
> Is there any possible way to execute some functions, only on
> closing the browser window(in firefox)?
As far as I know, no.
> closing the browser window(in firefox)?
As far as I know, no.
I don't accept change; I don't deserve to live.
Sacrifice is a painful, pure and beautiful thing.
Dammit, Jones, What the Hell Are Knoll Pointers?!
Sacrifice is a painful, pure and beautiful thing.
Dammit, Jones, What the Hell Are Knoll Pointers?!
Even if you could do that, Firefox closes so quickly that nobody could read it.
If somebody clicks the X, they want to close the program now. They don't want it to do any more.
If IE can do it, it is because IE has a nonstandard extension to web code. Never use nonstandard code.
If somebody clicks the X, they want to close the program now. They don't want it to do any more.
If IE can do it, it is because IE has a nonstandard extension to web code. Never use nonstandard code.
Daylight-saving time uses more gasoline
> Even if you could do that, Firefox closes so quickly that nobody could read it.
The 'onunload' event fires before the browser is closed and if an alert is fired, stops the window from closing so 'closes so quickly' is not an issue as such. The problem here is that the OP wants a function which would be fired _if and only if_ the browser is closed which I don't think is possible using any standard way.
The 'onunload' event fires before the browser is closed and if an alert is fired, stops the window from closing so 'closes so quickly' is not an issue as such. The problem here is that the OP wants a function which would be fired _if and only if_ the browser is closed which I don't think is possible using any standard way.
I don't accept change; I don't deserve to live.
Sacrifice is a painful, pure and beautiful thing.
Dammit, Jones, What the Hell Are Knoll Pointers?!
Sacrifice is a painful, pure and beautiful thing.
Dammit, Jones, What the Hell Are Knoll Pointers?!
AFAIK, you can't do that since before the document is being unloaded, submitting the form is an illegal action.
I don't accept change; I don't deserve to live.
Sacrifice is a painful, pure and beautiful thing.
Dammit, Jones, What the Hell Are Knoll Pointers?!
Sacrifice is a painful, pure and beautiful thing.
Dammit, Jones, What the Hell Are Knoll Pointers?!
![]() |
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Object required Message... cannot figure out
- Next Thread: Help with a dynamic dropdown menu
Views: 51905 | Replies: 27
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
ad ajax ajaxcode ajaxhelp alert alignment animate array asp boarder box boxes bug captchaformproblem card catch character close code codingproblem content cookies css database debug dependent design dialog div dom draganddrop dynamic editor element embed engine error eventhandlers explorer ext file firefox firehose flash focus font form forms function gears google hide html iframe image image() internet internet-explorer java javascript javascripts jquery js jump libcurl lists load maps modal mysql onclick onmouseover parameters pdf php player popup position post resize script scroll scrubber search select show size solutions source text twitter unicode validation variables web web-development webkit window xml \n






