Home >Web Front-end >JS Tutorial >How Can I Suggest a Filename for Data: URI Downloads?

How Can I Suggest a Filename for Data: URI Downloads?

DDD
DDDOriginal
2024-11-27 21:20:10130browse

How Can I Suggest a Filename for Data: URI Downloads?

Providing a Suggested Filename for Data: URI Downloads

When using data: URI to download data as a file, the browser typically generates a generic filename. However, it is often desirable to specify a suggested filename to the user for convenience.

Default Name Suggestion with the download Attribute

The HTML download attribute provides a solution for suggesting a default filename for data: URI downloads:

<a download='FileName' href='data:application/octet-stream;base64,SGVsbG8='>

This attribute works on most modern browsers, including Chrome, Firefox, Edge, Opera, desktop Safari 10 , iOS Safari 13 , and excludes IE11. When the user clicks the anchor tag, the browser will suggest the specified FileName as the default download name.

The above is the detailed content of How Can I Suggest a Filename for Data: URI Downloads?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn