0

The question is

How to show a confirmation box on closing a browser window ?

This question has been asked many times before, and previous answers, such as https://stackoverflow.com/a/333673/1442181 suggest to use the onbeforeunload event.

But, according to http://developer.mozilla.org/en-US/docs/Web/Events/beforeunload, "browsers may not display prompts created in beforeunload event handlers unless the page has been interacted with, or may even not display them at all."

I have a preview page after the user has filled some form, and I would like to show a confirmation prompt when the user leaves the page (except by clicking "back to edit" or "submit"). The preview page cannot be interacted with, so previous solutions seem to not work e.g. in the current firefox version.

(How to avoid the prompt on these two links is not part of the question and answerred in detail elsewhere.)

Christian
  • 527
  • 6
  • 19
  • 2
    The browsers that don't show those prompts do that for a reason. Bypassing that would make that measure useless. Not much you can do about it. – Ivar Sep 11 '17 at 18:49
  • 2
    If interacting with the page is the key to making the warning show, then you might be able to resolve this by making the preview part of the same page as the form (by hiding the form and showing the preview - whatever makes sense in your case). But ultimately, this is the browser's behavior and the browser can do as it likes. – Jon B Sep 11 '17 at 18:51
  • Okay, that's probably the way to go, thanks! – Christian Sep 11 '17 at 18:58

0 Answers0