About how to download the EXCEL and TXT files already in the project.

I encountered a strange problem today. Due to the demand, we need to make a template for downloading excel and txt on the page, and let customers write according to the template.

The results found that excel can be downloaded directly, txt directly jumped out of the page to display the contents of txt.

Download the posted code. It is an a tag.

<a target="_blank" data-icon="arrow-down" class="btn btn-green" href="file/addGroup.xls">下载EXCEL模板</a>

This excel can be downloaded directly.

However, it cannot be downloaded directly if it is replaced with txt, and it will jump to the content of txt.

So various search-oriented programming, with unremitting efforts, finally found a solution.

Daniel's explanation is txt, which can be directly recognized by the browser, so it will be opened directly.

Add an attribute on the a tag to download. The code is posted below.

<a target="_blank" data-icon="arrow-down" class="btn btn-green" href="file/groupMobile.txt" download="下载txt模板.txt" >下载txt模板</a>

Even if you record the problem and share it, you may forget it one day, so that you can help yourself when reading your blog.

Published 7 original articles · won 5 · visited 4120

Guess you like

Origin blog.csdn.net/blue_heart_/article/details/84623370