简体   繁体   中英

How to show jquery alert on page navigation

Am Navigate form one page to another, when am navigate form one page to another i want to jquery confirmation message with yes and no button,if i hit yes then go navigated page,if hit no then it still on current page.

For this am use jquery alert but alertbox automatically hide after few second. following is code

    var needToConfirm = false;
    var PageLeaveCount = $("#totalCount").val();        
    if (PageLeaveCount > 0) {
        needToConfirm = true;
    }
    window.onbeforeunload = confirmExit;

    function confirmExit() {
        if (needToConfirm) 
            swal({
                title: " Are you sure want to navigate?",
                text: "If you navigate out of scrutiny page without completing scrutiny asset on this stage will not move to next stage.",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "Yes",
                cancelButtonText: "No",
                closeOnConfirm: false,
                closeOnCancel: false
            },
      function (isConfirm) {
          if (isConfirm) {
              return true;
          }
          else {
              return false;
          }
      });



    }

Try by using callback of submit event handler and confirm -

$("form").submit(function(){
  return confirm('Are you sure you want to save this thing into the database?');
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM