| | |
Detect browser window closing event in Firefox -
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
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 5:04 am.
I don't accept change; I don't deserve to live.
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.
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.
![]() |
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Random Images on Refresh
- Next Thread: Dynamic Ajax Content and Jquery
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxhelp animate array automatically beta box bug calendar cart checkbox child codes column createrange() css cursor date debugger decimal design disablefirebug dom download dropdown editor element engine enter error explorer ext file firefox focus forms frameworks getselection google gwt html htmlform ie8 iframe images index internet java javascript jawascriptruntimeerror jquery jsf jsfile jsp jump listbox maps masterpage math menu microsoft mimic mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent pdf php player post problem programming progressbar prototype redirect regex runtime safari scale scriptlets scroll search select shopping size sql text textarea w3c web website window windowofwords windowsxp wysiwyg \n






