views:

385

answers:

3

How do I stop a browser refresh from happening when a flash object has focus inside a pop up window?

Yes, I abhor pop up windows too. Yet we have a flash questionnaire that is being wrecked from users who use refresh.

I also already have js in place that effectively blocks refresh, UNTIL the flash gets focus and the user presses refresh.

I have access to the Flash through our Flash developer, but he is uncertain of how to do this. The closest we could come up with was to use the fscommand trapallkeys, yet it does not appear to be working.

A: 

You can try trapping onbeforeunload, but there's not much else you can do.

See: http://stackoverflow.com/questions/158673/onbeforeunload-support-detection

and: http://stackoverflow.com/questions/447885/javascript-to-get-an-alert-to-redirect-when-closing-the-browser-window

Edit:

Refresh is an application-level event, not a client-level event. You're out of luck.

Diodeus
onbeforeunload is not going to help. It will not stop the refresh. This also has to support <b><i>every</i></b> major browser.
+1  A: 

Not going to happen.

Your best bet is a banner which says "DO NOT REFRESH THIS PAGE"

Gareth
+1  A: 

You'll never be able to block users from refreshing, either with their keyboard or pushing the refresh using their mouse. Instead of spending time trying to block it, I would suggest finding a way to support it.

A good way would be to use Local Shared Objects, to save current progress to the user's flash plugin. These can save variables locally on the users's machine, without using javascript or cookies.

Here's the documentation for flash shared objects.

Using this technique, when a user refreshes, simply reload the variables stored so far and display the questionnaire as it was when user left it.

sthg