How does the front end download pdf files in the http path?

such as the title, now there is a http://xxxx.pdf file on the server
what I thought at first was simply downloaded with a tag or location.href. Chrome test can only open pdf file preview, not download
Web search and found that a tag has a download attribute. After being full of joy, you can only open and browse
. Please ask if there is any way to download the file directly.
(I opened the page locally with an address of 127.0.0.1, which is different from the address of the pdf file. Does it mean that the download attribute does not take effect across domains)

Aug.25,2021

the default parsing behavior of the browser directly through the a tag cannot be controlled, but only through the response header to control the mode in which the browser parses. Returns the response header Content-disposition: attachment; of the resource Filename= file name. Pdf


set the response header of the pdf file Content-disposition: attachment on the server side. Clicking on the file link will download and will not open
reference: https://developer.mozilla.org.


opinions vary, but location.href is already quite easy to use. After previewing, there is a print icon in the upper right corner, click Save and download it. We have to talk to the client about this!


if the browser can parse, it seems that it will browse directly instead of downloading, unless it is a file that the browser does not recognize. And some browsers support the download attribute.

I feel that I need the backend to make it more reliable. The backend sets the response header (assuming the backend is php language):

// 
header('Content-type: application/pdf');
//  download.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');
// 
readfile('original.pdf');

Jump window.loaction.href


look at the browser
some support download download
some do not recognize pdf jump
Menu