473,387 Members | 1,585 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,387 software developers and data experts.

window.onbeforeunload doesn't always fire?

Hello everyone,
I have a chatroom. If someone leaves, I need to tell the server that
person has left. Currently i catch window.onbeforeunload to check if
the person tries to leave. I noticed that when I don't have a dialog
popup asking if the person really wants to leave, my Ajax-request code
doesn't always get sent to the server. Basically, the popup ensures my
beforeunload code gets executed. Why is this?

Also, when I try to stop the event, it will popup a dialog box that I
didn't make with the text "Are you sure you want to navigate away from
the page?". Is this a firefox/IE thing? Is there anyway to change the
text on the dialog box?

Thanks!
Jason Ho

Oct 22 '06 #1
2 6573
VK
Jason wrote:
Also, when I try to stop the event, it will popup a dialog box that I
didn't make with the text "Are you sure you want to navigate away from
the page?". Is this a firefox/IE thing? Is there anyway to change the
text on the dialog box?
You can *add* (not change) your own text below the default one in IE's
alert box. You cannot alter the alert box on other UA's AFAIK.

Also you seem to have a wrong idea of what onbeforeunload is doing. You
cannot seamlessly prevent navigation away from the current page against
visitor's will. Just think what would happen on the Web if it was
possible. The maximum you can do with onbeforeunload is to nag users
with "last chance to change your mind" alerts. You don't make these
alerts and you are not in power to cancel them. You trig them
automatically when returning false from your handler (thus overriding
the default action).

Oct 22 '06 #2
So what would be the best way to do some processing when the user
leaves/disconnects/closes the browser? Is it not a client-side
solution?

I was thinking I could make the server check every X seconds whether it
got a poll message from the client. If it didn't, it would log the user
out. Is this the most graceful solution, or is there something better I
can do? How does Gmail detect immediately when someone leaves the page
or closes the browser?

- Jason

VK wrote:
Jason wrote:
Also, when I try to stop the event, it will popup a dialog box that I
didn't make with the text "Are you sure you want to navigate away from
the page?". Is this a firefox/IE thing? Is there anyway to change the
text on the dialog box?

You can *add* (not change) your own text below the default one in IE's
alert box. You cannot alter the alert box on other UA's AFAIK.

Also you seem to have a wrong idea of what onbeforeunload is doing. You
cannot seamlessly prevent navigation away from the current page against
visitor's will. Just think what would happen on the Web if it was
possible. The maximum you can do with onbeforeunload is to nag users
with "last chance to change your mind" alerts. You don't make these
alerts and you are not in power to cancel them. You trig them
automatically when returning false from your handler (thus overriding
the default action).
Oct 23 '06 #3

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

Similar topics

1
by: rufus | last post by:
I have a function that checks whether the user is trying to navigate away from the page before saving all their data. I achieve this using the window.onbeforeunload javascript event. It fires...
9
by: ScooterMX | last post by:
I have a <a href="javascript:top.window.close()"><img src="exit.gif"></a> tag on my page that closes itself when you click on it. What I NEED is for it to put up a confirmation message that...
5
by: GEL | last post by:
Hi, I want to open a new browser window, let the user use that window for several minutes, and when they close, I'd like to change the page displayed in the original window. According to...
2
by: Vladimir | last post by:
It appears that this event (window.onbeforeunload) does not fire at least in Netscape 7.0 and 7.1. But window.onload and window.onunload events do! I really need this event handling in my...
8
by: sun | last post by:
I want to do clean up routine to my database when the browser is closed. I have my code in session-end - but it never fires when the browser closes. I cant do onbeforeunload as it will be fired...
1
by: Jason | last post by:
I am creating a Comet/Ajax chatroom system. When people go to the page, it will add them to the list of people in the room via window.onload. When they leave, disconnect, go to another page, or...
3
by: Andrew Poulos | last post by:
There's a HTA application that's running on a local computer (not from a URL) and the user can open a new HTML window by clicking a button The first time the user clicks the button the window...
29
Frinavale
by: Frinavale | last post by:
I have 2 FireFox (version 2) browser windows opened. One is the child of the other. When the user is finished with the child window, a method in the parent window is called to refresh a...
0
by: wpjoju | last post by:
i have this code which adds an event listener to a newly opened window but it doesn't seem to work in google chrome. the problem is window.addEventListener seem to work in chrome but if you do...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.