2023年12月21日发(作者:)

myBlob= ? (self) : Blob ;

if(String(this)==="true"){ //reverse arguments, allowing (true, "text/xml", "") to act as a callback payload=[payload, mimeType]; mimeType=payload[0]; payload=payload[1]; }

if(url && < 2048){ // if no filename and no mime, assume a url was passed as the only argument fileName = ("/").pop().split("?")[0]; = url; // assign href prop to temp anchor if(f(url) !== -1){ // if the browser determines that it's a potentially valid url path: var ajax=new XMLHttpRequest(); ( "GET", url, true); seType = 'blob'; ajax.οnlοad= function(e){ download(se, fileName, defaultMime); }; setTimeout(function(){ ();}, 0); // allows setting custom ajax headers using the return: return ajax; } // end if valid url? } // end if url?

//go ahead and download dataURLs right away if(/^data:[w+-]+[w+-]+[,;]/.test(payload)){

if( > (1024*1024*1.999) && myBlob !== toString ){ payload=dataUrlToBlob(payload); mimeType= || defaultMime; }else{

return Blob ? // IE10 can't do a[download], only Blobs: Blob(dataUrlToBlob(payload), fileName) : saver(payload) ; // everyone else can save dataURLs un-processed }

}//end if dataURL passed?

blob = payload instanceof myBlob ? payload : new myBlob([payload], {type: mimeType}) ;

function dataUrlToBlob(strUrl) { var parts= (/[:;,]/), type= parts[1], decoder= parts[2] == "base64" ? atob : decodeURIComponent, binData= decoder( () ), mx= , i= 0, uiArr= new Uint8Array(mx);

for(i;i

return new myBlob([uiArr], {type: type}); }

function saver(url, winMode){

if ('download' in anchor) { //html5 A[download] = url; ribute("download", fileName); ame = "download-js-link"; TML = ""; y = "none"; Child(anchor); setTimeout(function() { (); Child(anchor); if(winMode===true){setTimeout(function(){ ObjectURL();}, 250 );} }, 66); return true; }

// handle non-a[download] safari as best we can: if(/(Version)(d+).(d+)(?:.(d+))?.*Safari/.test(ent)) { url=e(/^data:([w-+]+)/, defaultMime);

if(!(url)){ // popup blocked, offer direct download: if(confirm("Displaying New DocumentnnUse to download, then click back to return to this page.")){ =url;} } return true; }

//do iframe dataURL download (old ch+FF): var f = Element("iframe"); Child(f);

if(!winMode){ // force a mime that will download: url="data:"+e(/^data:([w-+]+)/, defaultMime); } =url; setTimeout(function(){ Child(f); }, 333);

}//end saver

if (Blob) { // IE10+ : (has Blob, but not a[download] or URL) return Blob(blob, fileName); }

if(){ // simple fast and modern way using Blob and URL: saver(ObjectURL(blob), true); }else{ // handle non-Blob()+non-URL browsers: if(typeof blob === "string" || uctor===toString ){ try{ return saver( "data:" + mimeType + ";base64," + (blob) ); }catch(y){ return saver( "data:" + mimeType + "," + encodeURIComponent(blob) ); } }

// Blob but not URL support: