I have a page whose customer is selecting items, once selected I needed to check if the client will leave the current page because I need to alert him with a message like "Do you want to save your cart before leaving the page?" if yes save and continue the redirect, if not only redirects. I wanted to do to global redirects because I could pop up asking if it wanted and if after doing a window.location.href but I want it to serve everyone and not do the one by one the redirects ... I got a javascript method which does an action before redirecting, but even showing a popup it redirects without expecting customer response. I want to know if it has how I intercept the redirect and after its response I let it redirect
The js function
$(window).on("beforeunload", function(){
console.log("Deixando a pagina");
$('#modal-form-call').iziModal('open');
});
but there in the form it does not wait for the answer and it already redirects