dimanche 12 juin 2016

SweetAlert Confirm Message User Must click save in order to save canvas to jpeg


I've asked a similar question before with not much luck so I was hoping someone could help me out this time. In my drawing app I have a save button which allows the user to save the image as a jpg to their downloads. I have a prompt with SweetAlert on my onclick of the download button warning the user whether they want to save or not but my problem is that it saves anyways without input from the user. Can someone fill me in on how one might prevent it from downloading on its own? i've tried with e.preventDefault(); with no luck.. answers with code examples are welcome with open arms thanks very much

****************HTML**********************

<div>
    <a href="#" class="download" id="downloadLink"  download="img.jpg">
    <img src="./assets/tools/save.png" />
    </a>
  </div>

****************JAVASCRIPT**********************

$('#downloadLink').click(function (event) {




     swal({   title: "Are you sure you want to save?",  
            text: "This will save to your downloads",   
            type: "warning",  
             showCancelButton: true,   
            confirmButtonColor: "#f8c1D9",   
             confirmButtonText: "Yes, save it!",  
            closeOnConfirm: true 

            },



        function (isConfirm) {      
        if (isConfirm) {
        //swal("Deleted!");


            var dt = canvas.toDataURL('image/jpeg');
            this.href = dt;

            return true;



            } else {
                }

         return false; 
             });
            });

Aucun commentaire:

Enregistrer un commentaire