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>
May be some redirection is set when msgbox is triggered?
Try this:
Adding
Return false
will prevent any further processing from happening, and give the control about further executions to msgBox.