Victor
Victor

Reputation: 1271

Page Refreshes before jQuery dialog is closed

I created a function that replaces the window.alert function with my own function that utilizes jquery.dialog. The problem is that in some functions I call that function and reload the page right afterwards. It is supposed to refresh it when user clicks "OK", but it is reloading the page by itself before I even click "OK".

Here's an example of call sequence in a function:

function UpdateCertSucccess(result) {
customAlert("Hello World");
window.location.href = "./SomePage.aspx";
}

And here's my defined customAlert()

function customAlert(message) {
if (!isOpen) {
    $('#error-message-dialog').dialog({
        autoOpen: false, bgiframe: true, position: ['center', 100], modal: true, zIndex: '6000', title: 'R+L Carriers Message', width: 475, height: 250,
        buttons: {
            "OK": function () {
                $(this).dialog("close");
                isOpen = false;

            }
        }
    });
    var elements = message.split("|");
    $('#spMessage').text(elements[0]);
    $('#spCode').text(elements[1]);
    $('#spTime').text(elements[2]);
    $('#spServer').text(elements[3]);
    $('#error-message-dialog').dialog('open');
    isOpen = true;

       }
else {
    $('#spMessage').append("<br /><br />");
    $('#spMessage').append(message);
}
return false;

};

What could be causing the page reload before I close the dialog and how can I fix it? Thanks!

Upvotes: 1

Views: 682

Answers (2)

ori
ori

Reputation: 7847

Only browser popups (alert, confirm...) can suspend the execution of a function. You can't achieve the same effect yourself, so you'll need to improve your code, add an "onclose" callback option or something.

Upvotes: 2

Dau
Dau

Reputation: 8848

remove 'window.location.href = "./SomePage.aspx";' from 'UpdateCertSucccess()' function and place it in the function call after Ok click (ok click callback function where you closing the dialog box)

Upvotes: 2

Related Questions