0

I've created a page, where a user can edit data. What I want here is basically a confirmation dialogue with 3 choices, when the page is unloaded and there is still unsaved data:

  • yes - leave the page and save
  • no - leave the page and don't save
  • cancel - stay on the page and don't save

I know how I would go on about confirming page leaving and saving separately, but I don't really want to bug the user twice.

I'm not sure if this is possible at all, as it seems to be necessary to change the "do you want to leave"-dialogue of the browser. Is there a way around this? Any other solution is also welcome.

2
  • I'm pretty sure it's not possible, you're stuck with the browser default.
    – adeneo
    Jul 23, 2013 at 15:01
  • I'm not sure if browsers let you customize their "leave" dialog much. The general principle is that they assume you to be an ad network trying to confuse the user as much as possible into staying.
    – Katana314
    Jul 23, 2013 at 15:02

1 Answer 1

0

The onbeforeunload method does not let you edit what buttons will display. It doesn't even allow you to get rid of the default text, but you can add some text to it. What I recommend you do is just let the user know that there is unsaved data and if the user continues then it will be lost.

Another option is anchoring. Anchoring is when you add a function to objects that are in your page, so this option won't work if they hit the back button, go to a new URL, or close the window. But, let's say they hit log-out or a different button that you own, you can create a custom pop-up that does exactly what you're asking.

1
  • That's what I already suspected. Anchoring is not possible, users are not required to log in in order to edit something. inb4 bad idea: changes are reviewed manually, before going live. I guess I'll stick with the unload dialogue and maybe overlay the page to show what has changed. thx@all
    – hakai
    Jul 25, 2013 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.