< a href=” “download >

Browsers open files that can be opened, rather than downloading them. Adding the Download attribute solves this problem. However, this method is only applicable to same-origin scenarios and cross-domain files cannot be downloaded. Introduce the background of the project. The back end returns the URL address of my file. I need to download the file, and the file cannot be opened. So began a variety of search solutions…… The following are several articles I have studied: I have tried the following two schemes, and some files can be downloaded, while some files are still opened directly. Stackoverflow.com/questions/1… Stackoverflow.com/questions/3…



So continue to look for a plan…

Fortunately, I found two articles:

Blog.csdn.net/qq_43471802…

www.jianshu.com/p/477e3a4a9…

The final solution is to find a backend adjustment interface that returns a binary stream instead of a file URL. Then according to the solution described at the end of the second article above, the problem was finally solved. I wrote this article, mainly to share the knowledge of the implementation of cross-domain download process, took nearly a day and a half. It was the open world of programmers that saved me. The main purpose of writing this article is to help you to save development time. Keep it up!