直接上代码:
base64参数来源:
canvas.toDataURL("image/png");
function downloadFile(fileName, base64) {
const aLink = document.createElement('a');
const event = document.createEvent("MouseEvents");
event.initEvent('click', false, false); // initEvent 不加后两个参数在FF下会报错
aLink.download = fileName;
aLink.href = base64;
aLink.dispatchEvent(event);
}
es6 export:
export default (fileName, base64) => {
const aLink = document.createElement('a');
const event = document.createEvent("MouseEvents");
event.initEvent('click', false, false); // initEvent 不加后两个参数在FF下会报错
aLink.download = fileName;
aLink.href = base64;
aLink.dispatchEvent(event);
};