0
我試圖以helloWorld.png的形式下載文件,但它總是保存爲download.png。Javascript:如何使用特定的文件名保存圖片而不是download.png
你能幫我確定我錯過了什麼嗎?
var $container = $('#svg-container'),
// Canvg requires trimmed content
content = $container.html().trim(),
canvas = document.getElementById('thecanvas');
// Draw svg on canvas
canvg(canvas, content);
// Change img be SVG representation
var theImage = canvas.toDataURL('image/png');
$('#svg-img').attr('src', theImage);
function downloadWithName(uri, name) {
function eventFire(el, etype){
if (el.fireEvent) {
(el.fireEvent('on' + etype));
} else {
var evObj = document.createEvent('Events');
evObj.initEvent(etype, true, false);
el.dispatchEvent(evObj);
}
}
var link = document.createElement("a");
link.download = name;
link.href = uri;
eventFire(link, "click");
}
downloadWithName(theImage, "helloWorld.png")
http://jsfiddle.net/shanthisivanesan/a2FLx/22/
你認爲html5 download =「filename.ext」 –
我必須做這個programaticaly,就像我在jsfiddle例子中動態創建錨標籤一樣。你能讓我知道我錯過了什麼嗎? – user3646404
似乎直接與base64一起工作 - > ** http://jsfiddle.net/W48wQ/**,所以我猜測它與canvg()所做的任何操作以及base64的檢索方式有關。你等待畫布加載等? – adeneo