Untitled
unknown
javascript
2 years ago
925 B
9
Indexable
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Download PDF File</title> </head> <body> <button type="button" id="GetFile">Download</button> <script src="https://cdnjs.cloudFlare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> <script> $("#GetFile").on("click", function () { $.ajax({ url: "https://s3-us-west-2.amazonaws.com/s.cdpn.io/172905/test.pdf", method: "GET", xhrFields: { responseType: "blob", }, success: function (data) { var a = document.createElement("a"); var url = window.URL.createObjectURL(data); a.href = url; a.download = "myfile.pdf"; document.body.append(a); a.click(); a.remove(); window.URL.revokeObjectURL(url); }, }); }); </script> </body> </html>
Editor is loading...
Leave a Comment