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

查看:163
本文介绍了如何强制全面下载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天全站免登陆