在使用 data: URI 时,有没有办法指定建议的文件名? [英] Is there any way to specify a suggested filename when using data: URI?

查看:23
本文介绍了在使用 data: URI 时,有没有办法指定建议的文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如果您点击链接:

If for example you follow the link:

data:application/octet-stream;base64,SGVsbG8=

浏览器将提示您下载一个文件,该文件由超链接本身中以 base64 格式保存的数据组成.有没有办法在标记中建议默认名称?如果没有,是否有 JavaScript 解决方案?

The browser will prompt you to download a file consisting of the data held as base64 in the hyperlink itself. Is there any way of suggesting a default name in the markup? If not, is there a JavaScript solution?

推荐答案

使用 download 属性:

<a download='FileName' href='your_url'>

download 属性适用于 Chrome、Firefox、Edge、Opera、桌面 Safari 10+、iOS Safari 13+,而不是 IE11.

The download attribute works on Chrome, Firefox, Edge, Opera, desktop Safari 10+, iOS Safari 13+, and not IE11.

这篇关于在使用 data: URI 时,有没有办法指定建议的文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆