UNPKG

tiny-save-as

Version:

A tiny JavaScript utility library for file saving

2 lines 776 B
/* @license tiny-save-as v1.0.2 | (c) Qingrong Ke <keqingrong1992@gmail.com> (https://keqingrong.github.io/) */ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):e.saveAs=n()}(this,function(){"use strict";return function(e,n){if(navigator.msSaveOrOpenBlob)return navigator.msSaveOrOpenBlob(e,n),!0;if("undefined"!=typeof URL&&"download"in HTMLAnchorElement.prototype){var t=document.createElement("a");return t.href=URL.createObjectURL(e),t.download=n,t.addEventListener("click",function(){requestAnimationFrame(function(){URL.revokeObjectURL(t.href),t.remove()})},!1),t.dispatchEvent(new MouseEvent("click")),!0}return console.warn("[tiny-save-as] 该浏览器不支持文件保存"),!1}});