1. Use the <a> tag to complete <a href="/user/test/xxxx.txt" download="file name.txt">Click to download</a> In this way, when the user opens the browser and clicks the link, the file will be downloaded directly. However, there is a situation where, for example, files such as txt, png, jpg, etc. that the browser supports opening directly will not execute the download task, but will directly open the file. In this case, you need to add an attribute "download" to the a tag; The following is an example Move to the tag <a> to display the file path and complete the file path according to the path prompt. <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <a href="321.png" download="test.png">Click to download</a> </body> </html> If you need to download images uploaded from a web page, you may use the following methods Get the host domain name: location.hostname Get the port number: location.port 2. Use buttons for monitoring Button monitoring can be divided into two methods. One is window.open() var $eleBtn1 = $("#btn1"); var $eleBtn2 = $("#btn2"); //A known backend interface for downloading files: https://codeload.github.com/douban/douban-client/legacy.zip/master //Method 1: window.open() $eleBtn1.click(function(){ window.open("https://codeload.github.com/douban/douban-client/legacy.zip/master"); }); Second, form submission //Method 2: Through form $eleBtn2.click(function(){ var $eleForm = $("<form method='get'></form>"); $eleForm.attr("action","https://codeload.github.com/douban/douban-client/legacy.zip/master"); $(document.body).append($eleForm); //Submit the form to download $eleForm.submit(); }); Summarize The above are two methods of implementing click-to-download files on HTML pages that I introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! |
<<: Let's learn about the MySQL storage engine
>>: Detailed explanation of the usage of the rare tags fieldset and legend
Table of contents Main topic 1. Install Docker on...
Official documentation: https://dev.mysql.com/doc...
Configure the accelerator for the Docker daemon S...
There are significant differences between centos7...
I think this is a problem that many people have en...
MySQL needs to be upgraded to version 5.5.3 or ab...
1. Inline styles To add inline styles to the virt...
1. Pull the MySQL image Get the latest MySQL imag...
First of all, for security reasons, JavaScript ca...
See: https://www.jb51.net/article/112612.htm Chec...
I used the dialog in closure and drew a dialog wit...
Database SQL optimization is a common problem. Wh...
Table of contents background Solution New Questio...
The effect of this function is similar to vue的pro...
According to data analysis company Net Market Sha...