Home > Web Front-end > JS Tutorial > How to Pre-specify a Filename for a data: URI Download?

How to Pre-specify a Filename for a data: URI Download?

Susan Sarandon
Release: 2024-12-01 07:14:13
Original
876 people have browsed it

How to Pre-specify a Filename for a data: URI Download?

How to Specify a Suggested Filename When Using data: URI

Question:

When a data: URI is clicked, the browser prompts the user to download a file with the data encoded in base64. Is there a way to pre-specify a default filename for the downloaded file?

Answer:

Using the download Attribute:

Use the download attribute in the tag:

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

Availability:

  • Chrome
  • Firefox
  • Edge
  • Opera
  • Desktop Safari 10
  • iOS Safari 13

Note:

The download attribute is not supported in IE11.

Additional Information:

  • The download attribute is a suggested filename and may be overridden by the user.
  • The filename should include the file extension, such as .txt, .pdf, or .png.
  • The [href](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-href) attribute must be a valid data: URI.

The above is the detailed content of How to Pre-specify a Filename for a data: URI Download?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template