JavaScript 瀹炵幇鏂囦欢涓嬭浇骞堕噸鍛藉悕

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript 瀹炵幇鏂囦欢涓嬭浇骞堕噸鍛藉悕相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/type' title='type'>type   size   set   save   onload   nav   href   rev   stat   

绗竴绉嶆槸html瀹樼綉涓殑鏂规硶
<a href="/images/liang.jpg" download="鏂囦欢鍚嶇О">
HTML5 涓?a 鏍囩鎻愪緵浜嗕竴涓?filename 灞炴€э紝鍙互涓嬭浇鎴愭寚瀹氱殑 download 灞炴€у悕绉?br />杩欑鍚屾簮璁块棶鏄病鏈夐棶棰樼殑锛屼絾涓€璺ㄥ煙灏变笉琛屼簡锛岃瘯浜嗗叾瀹冩柟娉曪紝涓嶆槸鎶ヨ法鍩熼敊璇紝灏辨槸鍦ㄥ綋鍓嶉〉闈㈡墦寮€鏂囦欢锛屼綋楠岀浉褰撲笉濂姐€?br />
绗簩绉嶆柟妗堟瘮杈冮€氱敤
/** * 鑾峰彇 blob * url 鐩爣鏂囦欢鍦板潃 */ function getBlob(url) { return new Promise(resolve => { const xhr = new XMLHttpRequest(); xhr.open(鈥楪ET鈥?span class="token punctuation">, url, true); xhr.responseType = 鈥榖lob鈥?span class="token punctuation">; xhr.onload = () => { if (xhr.status === 200) { resolve(xhr.response); } }; xhr.send(); }); } /** * 淇濆瓨 blob * filename 鎯宠淇濆瓨鐨勬枃浠跺悕绉? */ function saveAs(blob, filename) { if (window.navigator.msSaveOrOpenBlob) { navigator.msSaveBlob(blob, filename); } else { const link = document.createElement(鈥榓鈥?span class="token punctuation">); const body = document.querySelector(鈥榖ody鈥?span class="token punctuation">); 銆€銆€銆€ link.href = window.URL.createObjectURL(blob); link.download = filename; // fix Firefox link.style.display = 鈥榥one鈥?span class="token punctuation">; body.appendChild(link); link.click(); body.removeChild(link); window.URL.revokeObjectURL(link.href); } } /** * 涓嬭浇 * @param {String} url 鐩爣鏂囦欢鍦板潃 * @param {String} filename 鎯宠淇濆瓨鐨勬枃浠跺悕绉? */ function download(url, filename) { getBlob(url).then(blob => { saveAs(blob, filename); }); }
 

以上是关于JavaScript 瀹炵幇鏂囦欢涓嬭浇骞堕噸鍛藉悕的主要内容,如果未能解决你的问题,请参考以下文章

Linux WordPress 璁块棶鍩熷悕涓嬭浇鏂囦欢

涓€涓猘jax瀹炵幇琛ㄥ崟涓婁紶鏂囦欢鐨勭鍣?formdata

Spring Cloud Alibaba锛堜簩锛?閰嶇疆涓績澶氶」鐩€佸閰嶇疆鏂囦欢銆佸垎鐩綍瀹炵幇

濡備綍鍦ㄤ娇鐢╒ue鐨勬儏鍐典笅瀹炵幇Electron鎵撳紑鏂囦欢淇濆瓨瀵硅瘽妗嗭紵

python鎺ュ彛鑷姩鍖?-post鏂囦欢涓婁紶