最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Can you set filename for "save as" on an image with a data url? - Stack Overflow

programmeradmin3浏览0评论

I have an image like this:

<img src="data:image/jpeg;charset=utf-8;base64,/9j...">

When I right click on the image and choose 'save as', the save dialog es up with "download.jpg" as the filename. I'd like to choose a different default filename. Adding a download tag on the img element doesn't seem to work. Is there some way to add a name to this?

I've seen this, but its about <a> tags: Is there any way to specify a suggested filename when using data: URI?

I have an image like this:

<img src="data:image/jpeg;charset=utf-8;base64,/9j...">

When I right click on the image and choose 'save as', the save dialog es up with "download.jpg" as the filename. I'd like to choose a different default filename. Adding a download tag on the img element doesn't seem to work. Is there some way to add a name to this?

I've seen this, but its about <a> tags: Is there any way to specify a suggested filename when using data: URI?

Share edited May 23, 2017 at 12:10 CommunityBot 11 silver badge asked Aug 19, 2016 at 8:04 B TB T 61.2k36 gold badges198 silver badges211 bronze badges 6
  • Possible duplicate of How to control base64 images when user saves as – Adnan Umer Commented Aug 19, 2016 at 8:15
  • 1 stackoverflow./questions/39034022/… – Maciej Sikora Commented Aug 19, 2016 at 8:22
  • 1 @MaciejSikora now because of you I am in an infinite loop looking for some dupe... – Kaiido Commented Aug 19, 2016 at 8:32
  • 1 I think it's a no-go... The closest I've got is this : plnkr.co/edit/biG96etB4CL2K3mtTMBW?p=preview Try from FF, in windowed mode, and then choose "View Image" in your context menu. Finally, look at the title of your page. (yes all this just for that...) – Kaiido Commented Aug 19, 2016 at 9:01
  • I think you're probably right Kaiido : / – B T Commented Aug 19, 2016 at 20:56
 |  Show 1 more ment

1 Answer 1

Reset to default 3

Maybe you can try something like this using caman.js. Here is a example how it works. I know that it's not exactly what you want but take a look. DEMO

You can also use the <a> tag to do that but it will download on click.

<a download="logo.png" href="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7">Download transparent png</a>
发布评论

评论列表(0)

  1. 暂无评论