fnz-base.js 951 B

123456789101112131415161718192021222324
  1. var fnz = (function () {
  2. return {
  3. getEl: function (id) { return document.getElementById(id); },
  4. scrollIntoViewById: function (id) { fnz.getEl(id).scrollIntoView(true); },
  5. downloadFile: function (filename, contentType, content) {
  6. // Create the URL
  7. const file = new File([content], filename, { type: contentType });
  8. const exportUrl = URL.createObjectURL(file);
  9. // Create the <a> element and click on it
  10. const a = document.createElement("a");
  11. document.body.appendChild(a);
  12. a.href = exportUrl;
  13. a.download = filename;
  14. a.target = "_self";
  15. a.click();
  16. // We don't need to keep the object URL, let's release the memory
  17. // On older versions of Safari, it seems you need to comment this line...
  18. URL.revokeObjectURL(exportUrl);
  19. a.remove();
  20. }
  21. }
  22. })();