I have an Embed PDF File inside object HTML Tag it shows up well what I want to achieve is I have an external HTML Button While I clicked on it it will download the Embed PDF in my computer using jQuery and display a success download message using SweatAlert2 Plugin .
HTML:
<object data="myfile.pdf" class="w-100" height="665"></object>
<button type="button" id="downloadButton" class="btn btn-primary">Download PDF</button>
JS:
(function ($) {
"use strict";
$("#downloadButton").on("click", function (e) {
e.preventDefault();
Swal.fire({
icon: "success",
title: "The file is downloaded successfully!",
showConfirmButton: false,
timer: 1500,
});
});
})(jQuery);
Note: I know that the download button already exists in embed PDF but I want to create an external one with my custom design.
Just as an example from GitHub, it works. https://github.com/eligrey/FileSaver.js
(function ($) {
"use strict";
$("#downloadButton").on("click", function (e) {
e.preventDefault();
// Use File saver code by following https://github.com/eligrey/FileSaver.js
Swal.fire({
icon: "success",
title: "The file is downloaded successfully!",
showConfirmButton: false,
timer: 1500,
});
}) })(jQuery);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.