onbeforeunload doesn't work in Safari

J

jennyw

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
 
J

Joshie Surber

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.
 
M

Michael Winter

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
 
V

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.
 
V

VK

Duncan said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top