如何在临时文件夹中保存图像

时间:2019-04-22 07:11:24

标签: javascript jquery

要获取DIV屏幕截图,请使用domtoimage.js文件,

https://ourcodeworld.com/articles/read/38/how-to-capture-an-image-from-a-dom-element-with-javascript 通过使用此文件进行下载,但是如何在下载之前将该文件保存到temp文件夹中。

function exportAsImage(){
    var result= $('#dashboardChartData').text();
    var nameOfChart=$('#exportAsImage').val();
    var node = document.getElementById("dashboardChartData");

    if(result.trim()!="No Data Available."){
        $('#simplemodal-overlay').css('display','block');     
        domtoimage.toPng(node).then(function(dataUrl) {
            var img = new Image();
            img.src = dataUrl;
            var link = document.createElement("a");
            link.download =  nameOfChart+".png";  
            $('#simplemodal-overlay').css('display','none');
            link.href = img.src;        
            localStorage.setItem(img.src, link.download );
            link.dispatchEvent(new MouseEvent(`click`, {bubbles: true, cancelable: true, view: window}));
            link.remove();
        });
    } else {
        bootbox.alert({ 
            size: 'small',
            title :'Alert',
            message: "No Data Available", 
        });     
    }   
}

0 个答案:

没有答案