Open modality of confirmation before sending

1

I want to open a modal to confirm if you are sure to perform the action, but send it directly as I solve it?

I have several links href = 'envaluacion / primera' the first string and the first word is changing is dynamic

$('.envios').click(function() {

  swal({
      title: "Aviso",
      text: "Esta seguro que desea salir?",
      type: "warning",
      showCancelButton: true,
      confirmButtonClass: "btn-danger",
      confirmButtonText: "Salir",
      cancelButtonText: "Cancelar",
      closeOnConfirm: false,
      closeOnCancel: false
    },
    function(isConfirm) {
      if (isConfirm) {
        location.href = "http://www.pagina1.com";
      } else {
        swal("Cancelado", "Usted esta aqui", "error");
      }
    });

});
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css" media="screen" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script>

<a href='envaluacion/primera' class="envios">Irse
    
asked by hubman 09.04.2018 в 06:48
source

1 answer

1

You must use promises as in the documentation , before this you must add the correct script (cdn) to your document.

If you want to get the href of your clicked link, simply access this.href since this will refer to the tag <a>

<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>

$(function() {
	$('.envios').click(function(e) {
		e.preventDefault();
		swal({
			title: "Aviso",
			text: "Está seguro que desea salir ? ",
			icon: "warning",
			buttons: true,
			dangerMode: true,
		})
		.then((willDelete) => {
			if (willDelete) {
            //Mensaje Opcional
            swal("Usted será redireccionado", {
            	icon: "success",
            });
            console.log(this.href);
            // redirección location.href = this.href
        } else {
        	swal("Canceceló la acción");
        }
    });
	});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<a href='envaluacion/primera' class="envios">Irse</a>
<a href='envaluacion/segunda' class="envios">Irse a Otra</a>
    
answered by 09.04.2018 / 07:20
source