jquery.AreYouSure icon indicating copy to clipboard operation
jquery.AreYouSure copied to clipboard

Firing custom method instead of the alert

Open AlainPilon opened this issue 10 years ago • 4 comments

Since the standard alert box is so ugly, it would be nice for the library to allow us to pick a custom function for fire instead of the alert.

AlainPilon avatar Nov 26 '14 20:11 AlainPilon

Unfortunately this is not possible. All current browsers to my knowledge only support the "standard dialog" for message passed back on the beforeunload event. It is possible to display your own dialog if you're navigating away from the page via a link, but not if you're navigating via the back button, manually typing in a URL, or closing a tab.

If you're in control of the navigation, you could wire up your own code quickly. e.g.:


// Turn on silent mode.
$('form').areYouSure( {'silent':true} );

// In your own page exit code
if ($('form').hasClass('dirty')) {
    // Show your custom fancy dialog
}

Hope this helps.

codedance avatar Nov 28 '14 04:11 codedance

So its currently not possible to fire for example, a Bootstrap Modal to use as confirmation instead of the standard alert box?

dyentite avatar Dec 09 '14 09:12 dyentite

@dyentite You can do this using the code example above on your own "page exit" event. If you want to use/leverage the browser's event (e.g. closing a tab/window), you'll need to use the browsers own dialog. (This is the same way Gmail works).

codedance avatar Dec 15 '14 01:12 codedance

I'm showing a "please wait " modal after any link is clicked. the problem is that after the user push the STAY button this button stills on the screen, how can I trigger a method to hide my modal by pushing stay button? is there any way to customize the the cancel/stay button behaviour?

kavehmb avatar Oct 09 '15 18:10 kavehmb