Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

confirmation before exit dialog

In most pages, if your doing an action, (like editing, creating), and when I attempt to exit, it mostly prompts me if I really want to exit. The dialog gives me two options: leave or cancel and continue. How do you accomplish this in JavaScript? Do I have to use a meta element? And please don't mention beforeunload, unless it's the true and only way to accomplish this.

like image 341
slice Avatar asked Jun 17 '13 08:06

slice


People also ask

How do you show a dialog to confirm that the user wishes to exit an Android activity?

. setMessage( "Are you sure you want to exit?" )

How do I stop dialog closing?

Set the onClickListener during the creation of the dialog to null. Then set a onClickListener after the dialog is shown.


1 Answers

Why not mention onbeforeunload? It's the built in way to do so, and I don't see a problem using it.

function myConfirmation() {
    return 'Are you sure you want to quit?';
}

window.onbeforeunload = myConfirmation;
like image 56
casraf Avatar answered Sep 18 '22 13:09

casraf