首页 > 其他分享 >html2canvas 下载图片

html2canvas 下载图片

时间:2022-12-07 14:48:00浏览次数:45  
标签:canvas app setAttribute html2canvas clickEvent document 下载 图片

html2canvas(that.$app, {
                'width' : that.$app.get(0).offsetWidth,
                'height' : that.$app.get(0).scrollHeight,
                'background' : '#fff',
                'scale': window.devicePixelRatio || 1,
                'onclone' : function(cloneDoc) {    
                },
                onrendered : function(canvas) {
                    var base64Data = canvas.toDataURL("image/png");
                    // 创建a标签 并设置其相关属性,最后触发其点击事件
                    let a = document.createElement("a")
                    let clickEvent = document.createEvent("MouseEvents");
                    a.setAttribute("href", base64Data)
                    a.setAttribute("download", "绩效下载")
                    a.setAttribute("target", '_blank')
                    clickEvent.initEvent('click', true, true)
                    a.dispatchEvent(clickEvent);
                        
                }
            });

 

标签:canvas,app,setAttribute,html2canvas,clickEvent,document,下载,图片
From: https://www.cnblogs.com/qiao20/p/16962995.html

相关文章