Blob知識

1,創建blob對象

var aBlob = new Blob( array, options );

參考:https://developer.mozilla.org/zh-CN/docs/Web/API/Blob/Blob

2,文件重命名
Demo下載(文件重命名)

var aFileParts = ['<a id="a"><b id="b">hey!</b></a>']; // 一個包含DOMString的數組
var oMyBlob = new Blob(aFileParts, {type : 'text/html'})
function saveAs(blob, filename) {
					if(window.navigator.msSaveOrOpenBlob) {
						navigator.msSaveBlob(blob, filename);

					} else {

						var link = document.createElement('a');

						var body = document.querySelector('body');

						link.href = window.URL.createObjectURL(blob);

						link.download = filename;

						// fix Firefox

						link.style.display = 'none';

						body.appendChild(link);

						link.click();

						body.removeChild(link);

						window.URL.revokeObjectURL(link.href);

					};

				}
saveAs(oMyBlob,'test.html')
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章