如何强制完全下载链接上的txt文件? [英] How to force fully download txt file on link?

查看:40
本文介绍了如何强制完全下载链接上的txt文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的文本文件,我想通过任何锚标记链接下载该文件.

I have one simple text file and I want to download that file on any anchor tag link.

但是当我点击那个链接时,txt 文件显示给我但没有下载.

But when I click on that link txt file shown me but not downloaded.

我试过这个代码

<html>
    <head>
        <title>File</title>
    </head>
    <body>
        <a href="test.txt">Click here</a>
    </body>
</html>

推荐答案

点击链接时下载文件(而不是导航到文件):

Download file when clicking on the link (instead of navigating to the file):

<a href="test.txt" download>Click here</a>

下载文件并将其重命名为 mytextdocument.txt:

Download file and rename it to mytextdocument.txt:

<a href="test.txt" download="mytextdocument">Click here</a>

下载属性指定当用户单击超链接时将下载目标.

The download attribute specifies that the target will be downloaded when a user clicks on the hyperlink.

此属性仅在设置了 href 属性时使用.

This attribute is only used if the href attribute is set.

该属性的值将是下载文件的名称.对允许值没有限制,浏览器会自动检测正确的文件扩展名并将其添加到文件中(.img、.pdf、.txt、.html 等).

The value of the attribute will be the name of the downloaded file. There are no restrictions on allowed values, and the browser will automatically detect the correct file extension and add it to the file (.img, .pdf, .txt, .html, etc.).

如果省略该值,则使用原始文件名.

If the value is omitted, the original filename is used.

这篇关于如何强制完全下载链接上的txt文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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