Prevent Unload JS (5)

1 Name: alex : 2009-07-16 01:40 ID:fP8KWoFU

Hi guys, this is my first time on this site, so don't be too hard on me. I don't know if there's any web guys, but I'll ask anyway.

Anyway, I've spent the whole day trying to find a way to prevent the unload handler from triggering in browsers. I need to do this once so as to display a [pleasing] message to the user and to try and keep them on the page (quite possibly with one of those talking flashes). If the user wants to still leave thereafter, then they are free to do so.

From what I've seen so far, the unload handler will fire whatever custom function there is, but will not stop, which defeats the purpose of me trying to play an animated message to the user if their browser will just continue on.

I'm pretty sure I've seen something like this on porn sites, but I can't quite start looking up porn sites at random hoping to find the script I need while at work...

So, I come here to ask for help. I would really appreciate it if anyone has input/samples/examples to provide me.

Thanks in advance!

2 Name: #!/usr/bin/anonymous : 2009-07-16 14:24 ID:Heaven

To stop the browser from continuing you need to add something within your onunload code that pauses for user input. A pop-up is the most obvious way of doing this, but might not be what you want.

3 Name: Alex : 2009-07-16 18:56 ID:fP8KWoFU

Yeah, I thought about that too, but the only way to pause it is to have some sort of a modal window come up on top of the site, which is not what I want.

I have a feeling that browsers will just ignore any attempts to cancel the unload event, most likely for usability reasons, which I understand.

I was thinking about opening an identical window behind the current one and then let the other one close, but I've read that window.open() commands will be ignored in the unload event...

Anyone have other suggestions?

4 Name: Alex : 2009-07-16 19:10 ID:fP8KWoFU

So, as I thought, the browsers will ignore attempts to open new windows at the unload event, so that being my last resort, I would have to explain to my manager that its just not a viable idea.

Well, thanks for the help anyway!

5 Name: #!/usr/bin/anonymous : 2009-07-17 01:58 ID:kTPeCWUA

Would a return true; or return false; do anything?
That or maybe just open up a new window from the unload handler.

I would take a look at how lastmeasure does it.

This thread has been closed. You cannot post in this thread any longer.