jConfirm will never โreturnโ anything because this โevent is drivenโ.
jConfirm waits for the user to make a decision, and then he will call a callback function that will handle the response. But jConfirm will not block the flow of code, as standard confirm(...) does.
So, if your previous code looks like this:
// ask for a decision var answer = confirm("Leave website?"); // the whole script stops until the user has made a decision! // process answer if (answer){ alert("Bye bye!"); // the script waits here until the user has clicked "ok" window.location = "http://www.google.com/"; } else{ alert("Thanks for sticking around!"); // the script waits here until the user has clicked "ok" }
it should look like this in jQuery:
// previous code // show confirm dialog but the script will not wait, the script execution goes forward jConfirm('Leave website?', 'Confirmation Dialog', function(answer) { // this is the callback function of the jConfirm dialog we made // we arrive here when the user has made a decision // the answer is true, he wants to leave if (answer){ // show a jAlert box jAlert("Bye Bye!", "Some Title", function() { // this is the callback function of the jAlert box // we arrive here when the user has clicked "ok" // send him to google window.location = "http://www.google.com/"; }); } else{ // show a jAlert box without any callback jAlert("Thanks for sticking around!", "Some Title"); } }); // the code that follows here will be immediately executed // because unlike confirm(), jConfirm() will not block // the code execution flow
And to illustrate:
Standard JavaScript Confirmation Stream () JavaScript
| | | \/ confirm() waits for an answer... no further code will be executed until the user has made a decision | | \/ handle the user answer | | \/ further code execution
JConfirm execution thread
| | \/ -------> jConfirm Dialog | | | | | \/ | Callback function | when the user has made | a decision. | (handle the answer here) | | \/ further code execution
sled source share