my code:
alert('Some message');
Question 1:
How to execute code that comes after alert()
when user finished interacting with alert box?
Question 2:
How to detect if user pressed OK
or Cancel
on alert box ?
To click on the Ok button on alert, first of all we have to switch to alert with switchTo(). alert() method. Next, to click on the Ok button, we have to use accept() method.
Unfortunately there is no built in one-liner for displaying a simple alert in jQuery UI, but it is easy to add an own one. This is a standard jQuery UI dialog displayed using one line of code. It follows the same theme as the rest of the jQuery UI widgets used on the site and it behaves like a normal modal dialog.
One of the nice things about the built-in JavaScript alert is that - unlike virtually anything else in JavaScript - it's synchronous. It's completely blocking, and no other code will execute until it's been dismissed.
Use the alert() function to display a message to the user that requires their attention. This alert box will have the OK button to close the alert box. The alert() function takes a paramter of any type e.g., string, number, boolean etc. So, no need to convert a non-string type to a string type.
Question 1:
The alert
method blocks execution until the user closes it:
alert('Some message');
alert('doing something else after the first alert is closed by the user');
Question 2:
use the confirm
function:
if (confirm('Some message')) {
alert('Thanks for confirming');
} else {
alert('Why did you press cancel? You should have confirmed');
}
The code after the alert()
call won't be executed until the user clicks ok to the alert, so just put the code you need after the alert()
call.
If you want a nicer floating dialog than the default javascript confirm()
popup, see jQuery UI: floating window
var r = confirm("Press a button!");
if (r == true) {
alert("You pressed OK!");
}
else {
alert("You pressed Cancel!");
}
http://jsfiddle.net/rlemon/epJGG/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With