Stop page from redirecting after msgbox is showed

68 views Asked by At

I want the page to stop from redirecting when the msgBox is displayed and wait untill user has pressed a button on the box.

I am able to display the msgbox when the page unloads, but still the page redirects to another webpage without waiting for user's input.

<script>
    $(window).bind('beforeunload', function () {
        msgbox();
    });

    function msgbox() {

        $.msgBox({
            title: "Confirmation",
            content: "Do you agree with the information provided?",
            type: "confirm",
            buttons: [{ value: "Yes" }, { value: "No" }],
            success: function (result) {
                if (result == "Yes") {
                    window.location.replace("somepage/controller/func2");
                } else {
                    window.location.replace("somepage/controller/func1");
                }
            }
        });
    }
</script>
1

There are 1 answers

2
harkirat1892 On

May be some redirection is set when msgbox is triggered?

Try this:

$(window).bind('beforeunload', function () {
    msgbox();
    return false;
});

Adding Return false will prevent any further processing from happening, and give the control about further executions to msgBox.