【问题标题】:SweetAlert Confirm Message User Must click save in order to save canvas to jpeg [duplicate]SweetAlert 确认消息用户必须单击保存才能将画布保存为 jpeg [重复]
【发布时间】:2017-07-05 01:40:54
【问题描述】:

我之前问过一个类似的问题,但运气不佳,所以我希望这次有人能帮助我。在我的绘图应用程序中,我有一个保存按钮,允许用户将图像作为 jpg 保存到他们的下载中。我在点击下载按钮时有一个 SweetAlert 提示,警告用户他们是否要保存,但我的问题是它在没有用户输入的情况下无论如何都会保存。有人可以告诉我如何阻止它自行下载吗?我试过 e.preventDefault();没有运气..欢迎张开双臂回答代码示例非常感谢

****************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; 
             });
            });

【问题讨论】:

    标签: javascript jquery if-statement html5-canvas sweetalert


    【解决方案1】:

    来自甜蜜警报演示页面close Confirm: falsecloseOnCancel: false

    工作示例: https://jsfiddle.net/cristyansv/gj62h9ab/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-28
      • 1970-01-01
      • 2011-05-10
      • 1970-01-01
      • 1970-01-01
      • 2017-01-29
      相关资源
      最近更新 更多