admin管理员组文章数量:1389903
I use this code to save images in Javascript :
window.location.href = grid.toDataURL("image/png").replace("image/png", "image/octet-stream");
The code works, but the file saved doesn't have any extension, I have to rename it manually.
My question is how can I put the extension at the end ?
Thank you.
I use this code to save images in Javascript :
window.location.href = grid.toDataURL("image/png").replace("image/png", "image/octet-stream");
The code works, but the file saved doesn't have any extension, I have to rename it manually.
My question is how can I put the extension at the end ?
Thank you.
Share Improve this question asked Dec 7, 2013 at 17:47 jbltxjbltx 1,3152 gold badges19 silver badges37 bronze badges1 Answer
Reset to default 6toDataURL
produces a data-uri not a file name so extensions doesn't apply in this case.
A data-uri is simply a text encoded version of the binary content which some browsers can read as a file - a data-stream if you will. As data streams doesn't have any filename you can't attach one.
You can work around this by setting an anchor tag like this:
<a id="imageLink" href="data-uri-here" download="myFilename.png">
Click to download
</a>
In JavaScript you can set these attributes dynamic:
imageLink.href = grid.toDataURL();
imageLink.download = 'myOtherFilename.png';
本文标签: javascriptMissing extension when saving image from canvasStack Overflow
版权声明:本文标题:javascript - Missing extension when saving image from canvas - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744653554a2617830.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论