Sanjeev
Sanjeev

Reputation: 855

Pausing the execution of the script using a customize alert box

I have overridden the default alert box with a custom dialog box. But I want the script to be paused until the cancel button on the dialog box is clicked. How to achieve it using javascript or jquery ?

P.S. : I am trying to make a dialog box which has the same functionality as an alert box.

Upvotes: 0

Views: 1388

Answers (2)

Rickyrock
Rickyrock

Reputation: 328

I will use dynamic HTML.

var $divAlert = $("<div>Are you sure going to next step?</div>");

$divAlert.dialog({
                autoOpen: true,
        height: "auto",
        width: "auto",
        modal: true,
        buttons: {
            "OK": function(){
                //Your Code/Logic goes here
            },
                    "Cencel": function(){
                        $(this).dialog("close");
                    },
        }
});

you can also customize in temrs of design your dialog just add class.

like,

dialogClass: "MyDialog"

Upvotes: 0

Gigo
Gigo

Reputation: 3264

You can not write blocking code in javascript as it is single threaded and runs on the same thread as the UI, see here: Blocking "wait" function in javascript?

You could do it via callbacks or events that get fired when your custom alert box gets closed.

function CustomAlert(message, callback)
{
    alert(message);
    callback();
}

function CodeWhichGetsBlocked()
{
    DoSomething();
    CustomAlert("continue?", function() {
        DoSomething();
    });
}

Upvotes: 1

Related Questions