Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplaying a custom dialog when the user exits the browser?
    text
    copied!<p><strong>Yes, I realize this is horrible UI and bad accessibility wise, but I am forced to seek out the options due to contracted work ( to which I didn't initially agree upon and am stuck with ).</strong></p> <p><strong>I know that you can assign an event handler to <code>onbeforeunload</code> like:</strong></p> <pre><code>window.onbeforeunload = function() { return 'You have unsaved changes!'; } </code></pre> <p>That would bring about a dialog generated by the OS/browser which cannot be customized. It would ask you to Cancel your request or go on.</p> <p>So far it seems the only way I can display any custom-ness is by inserting a <code>window.open</code> in that event handler:</p> <pre><code>window.onbeforeunload = function() { var x = window.open('modal.html'); } </code></pre> <p>This would most likely get blocked by any modern browser as a "popup". I have to display an entirely new page with my dialog, but this seems to be the only way to meet the demand.</p> <p><strong>Is this pretty much the only option I have? Other than forcefully telling the client it isn't recommended to do this?</strong> </p> <p>The only other option would be relying on the user to hit "Cancel request" and then insert the dialog.</p> <p>Questions I have <strong>already</strong> looked at:</p> <ul> <li><a href="https://stackoverflow.com/questions/1889404/jquery-ui-dialog-onbeforeunload">jQuery UI Dialog OnBeforeUnload</a></li> <li><a href="https://stackoverflow.com/questions/276660/how-can-i-override-the-onbeforeunload-dialog-and-replace-it-with-my-own">How can I override the OnBeforeUnload dialog and replace it with my own?</a></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload