473,326 Members | 2,805 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,326 software developers and data experts.

onbeforeunload doesn't work in Safari

Hi,

I'd like to use onbeforeunload to submit a form before leaving a page.
This works in Firefox and IE. Safari, however, blithely ignores this.

Does anyone know of a workaround for Safari? Or another way to do the
same thing in Safari? (that is, intercept a request to leave the page).
I tried Safari 2.02 on Tiger.

Thanks!

Jen

Nov 11 '05 #1
6 23040
> I'd like to use onbeforeunload to submit a form before leaving a page.
This works in Firefox and IE. Safari, however, blithely ignores this.

Does anyone know of a workaround for Safari? Or another way to do the
same thing in Safari? (that is, intercept a request to leave the page).
I tried Safari 2.02 on Tiger.


Any reason why window.onunload won't work? Maybe use both, and have
onbeforeunload set a flag that onunload checks for to work around
things like the Google toolbar that disable onunload.

Nov 23 '05 #2
On 11/11/2005 01:43, jennyw wrote:
I'd like to use onbeforeunload to submit a form before leaving a page.
Why? If the user is leaving, it should be considered too late to do
anything.
This works in Firefox and IE. Safari, however, blithely ignores this.


Why shouldn't it? The beforeunload event is a Microsoft invention, so no
vendor is under any obligation to implement it. Even Opera doesn't, and
it probably implements more of Microsoft's proprietary features than any
other browser.

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Nov 23 '05 #3
VK
> I'd like to use onbeforeunload to submit a form before leaving a page.
This works in Firefox and IE. Safari, however, blithely ignores this.
Does anyone know of a workaround for Safari? Or another way to do the
same thing in Safari? (that is, intercept a request to leave the page).
I tried Safari 2.02 on Tiger.


<onbeforeunload> event handler is implemented only by browsers which
have "current page's state snapshot" mechanics.

What <onbeforeunload> is for:
1) to take the current page's state snapshot including each form
elements state/value and save in the data store on the client side: so
next time user comes on this page she will get it in the exactly same
state as she left it.

2) That's it!
What <onbeforeunload> is *NOT" for:
1) to nag users with idiotic questions:
- Are you sure you want to quit?
- Are you really really sure you want to leave now?
- Maybe you will stay here a bit more?
etc.

2) to sent/receive last minute data from server. Like:
- Sure I'll let you to leave... Just hold on for a couple of minutes
(hours) before I finish data exchange...
:-)

Safari and Konqueror are not such browsers, so they don't have
<onbeforeunload>. They are (as a greate amount of other wannabes)
rather featureless HTML/XML renderers. The only reason they are *so
far* taken into any account is that they are coming pre-installed with
Mac OS X and KDE for Linux respectively. So they are parasiting on some
users' mental inertion: it was here from the beginning, so I'll keep
using it. This tactic helped a lot to Internet Explorer to win the war,
but besides that it was at least a really powerful browser. I'm not
sure what their hope is on the long run.

Nov 23 '05 #4
VK wrote:
What <onbeforeunload> is for:
1) to take the current page's state snapshot including each form
elements state/value and save in the data store on the client side: so
next time user comes on this page she will get it in the exactly same
state as she left it.

2) That's it!
Err, no. onbeforeunload has one intended purpose which is to warn the user
that they are navigating away from the page and give the user the option to
decide whether or not they want to continue. That is the sole reason for
its existence.


What <onbeforeunload> is *NOT" for:
1) to nag users with idiotic questions:
- Are you sure you want to quit?
- Are you really really sure you want to leave now?
- Maybe you will stay here a bit more?
etc.
The question may be idiotic if asked in the wrong situation, but the
ability to ask such questions is an important part of making a useable web
application, and onbeforeunload is the only way to do it reliably.
2) to sent/receive last minute data from server. Like:
- Sure I'll let you to leave... Just hold on for a couple of minutes
(hours) before I finish data exchange...
:-)


You are correct on that point.
Nov 23 '05 #5
VK
Duncan Booth wrote:
Err, no. onbeforeunload has one intended purpose which is to warn the user
that they are navigating away from the page and give the user the option to
decide whether or not they want to continue. That is the sole reason for
its existence.

The question may be idiotic if asked in the wrong situation, but the
ability to ask such questions is an important part of making a useable web
application, and onbeforeunload is the only way to do it reliably.


If user wants to leave the site it means she *wants* to leave the site.
If she wants to go to the previous page it means that she *wants" to go
to the previous page. These are very basics of usability and proper
programming.
We may presume an unattended form submission or a link click on the
page - but this is easy to fix by standard event handlers on the page
itself. If someone used browser interface: toolbar button or menu
command or shortcut key - then there is no space for any guess or
presumption. User indeed wants what she asked for. Save the page state
using <onbeforeunload> and let her go.

But if you really cannot let someone out without one more final "Hell
f*** yes, I do!" confirmation, then... you're the king anyway, I guess.

Nov 23 '05 #6
VK wrote:
Duncan Booth wrote:
Err, no. onbeforeunload has one intended purpose which is to warn the
user that they are navigating away from the page and give the user
the option to decide whether or not they want to continue. That is
the sole reason for its existence.
> The question may be idiotic if asked in the wrong situation, but the
ability to ask such questions is an important part of making a
useable web application, and onbeforeunload is the only way to do it
reliably.


If user wants to leave the site it means she *wants* to leave the
site. If she wants to go to the previous page it means that she
*wants" to go to the previous page. These are very basics of usability
and proper programming.
We may presume an unattended form submission or a link click on the
page - but this is easy to fix by standard event handlers on the page
itself. If someone used browser interface: toolbar button or menu
command or shortcut key - then there is no space for any guess or
presumption. User indeed wants what she asked for. Save the page state
using <onbeforeunload> and let her go.


You and your users may be perfect, unfortunately my users aren't and they
make mistakes and sometimes click on links which result in navigating away
from a page without having saved their work. If a page contains a complex
form, and the user has entered some data but then attempts to navigate away
without saving, a simple yes/no request for confirmation is appropriate.

But if you really cannot let someone out without one more final "Hell
f*** yes, I do!" confirmation, then... you're the king anyway, I
guess.


Sorry, but my business is providing the users what they want, and since the
users ask for such confirmation, that is what they get.

Anyway, you are missing the point: onbeforeunload exists solely for the
purpose of generating a confirmation dialog before navigating away. That is
why Microsoft invented the event, and using it is so important in some
situations that the Mozilla team realised they had to adopt the same event
(albeit with a slightly incompatible interface). To say the event is not
intended for generating a warning dialog is simply wrong. Yes, it can also
be used in inappropriate situations to annoy users, but that does not
impact on its correct use.
Nov 23 '05 #7

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

Similar topics

2
by: Robert Oschler | last post by:
I have a web page where I want to make sure that an image HTTP request is successfully made before the page unloads. The request is made by setting the image element's SRC property to the desired...
1
by: Robert Oschler | last post by:
I've successfully attached to the "onclick" and several other events using AttachEvent(). But when I try to attach to the "onbeforeunload" event it doesn't work (the handler I've assigned is never...
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...
3
by: Tony | last post by:
OK - I know the mantra, so let's be clear: I'm working on a web application that we want to be able to simply warn the user that they might lose data (or the current application state - it's .NET)...
4
by: sowencheung | last post by:
the bug of onbeforeunload is so obvious! in IE 6 it will popup twice "sometimes" I am using the following code window.onbeforeunload = null; window.onbeforeunload = confirmExit; var...
1
by: David | last post by:
I am using a process to warn users when they leave a page that there have been changes made. I took the example directly from Microsoft example I found in searching for help on the event...
1
by: lee_youjin | last post by:
I needed to defect when the user is clicking the IE X button ( top right). so I could execute the cleanup function. I was able to detect it using onbeforeunload event. Now I need to call the...
1
Frinavale
by: Frinavale | last post by:
Introduction I've seen many questions asked about how to disable the browser's back button and in the past I've replied with "it's simply not possible". It's not a good idea to disable the back...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.