•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 397,851 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,322 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 17746 | Replies: 20 | 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."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
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."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
> 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."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
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."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
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."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
ajax apple asp beta bon browser browsers developer development echo email encryption europe firefox gecko home html internet internet explorer internet explorer 7 javascript leak linux memory microsoft mobile mozilla msdn news nintendo office open source open-source opera pda privacy security site software spoof sql super testing url users vista web webmail wii windows
- Previous Thread: Javascript is not working on Firefox
- Next Thread: change cursor from pointer to hand



Linear Mode