Home  >  Article  >  Web Front-end  >  How to Make PDF Links Downloadable in HTML without Opening Them in Browser?

How to Make PDF Links Downloadable in HTML without Opening Them in Browser?

Barbara Streisand
Barbara StreisandOriginal
2024-10-22 20:57:02941browse

How to Make PDF Links Downloadable in HTML without Opening Them in Browser?

How to Download PDFs Instead of Opening Them in Browser (HTML)

When linking to PDF files in HTML, they often automatically open in the browser, rather than prompting the user to download. However, there's a simple solution to make PDF links downloadable using HTML5.

Solution:

Add a "download" attribute to your element. This attribute informs the browser to offer the linked file as a download instead of opening it in the browser.

<code class="html"><a href="http://link/to/file.pdf" download="File Name">Download it!</a></code>

The "download" attribute can be set to any value, but it's recommended to provide a meaningful file name that helps identify the file to be downloaded.

Additional Information:

This method requires HTML5 support, which is widely available in modern browsers. However, for older browsers that don't support the "download" attribute, you can use JavaScript or other client-side techniques to achieve similar functionality.

The above is the detailed content of How to Make PDF Links Downloadable in HTML without Opening Them in Browser?. 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