How to download pdf via js click (no page skipping, no refresh)

var $eleForm = $("<form method="get"></form>")
$eleForm.attr("action", "xxxxxxx")
$(document.body).append($eleForm)
pdf  a  
<a href="xxxx" download></a>
Apr.10,2022

turn off the default opening function of the browser


not all browsers can open files. You can download it directly by changing it to Sogou browser or 360browser . I think you should be using Chrome browser now, so you will open PDF files. This function can be turned off in the settings. Chrome browser can open pictures and PDF files by default, and other files can be downloaded using the above method.


download this is a new attribute, which is not supported by some browsers. To download or open it directly, it is set by the backend interface content-Type


to fully support downloading, you need to rely on the backend

Menu