10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

IE11でblobがダウンロードできないの回避

Posted at

window.navigator.msSaveBlob を見てあげる。
あったらIE11?

		var file_data_uint8 = new Uint8Array(file_data);
		var blob = new Blob([file_data_uint8.buffer], { type: "application/zip" });
		var url = window.URL.createObjectURL(blob);
        var a = $('<a>').attr({href:url, download:name}).text(name);

aタグとURL作成したところIE11が反応しないので下記追加してあげる

		a.click(function(){
			if(window.navigator.msSaveBlob){
				console.log('IE11?');
				window.navigator.msSaveBlob(blob, name);
		  }
        }

おまけ file_dataデータがbase64の場合の変換

// base64 -> url || blob
function base642url(base64, opt){
	opt = opt ? opt : {type:'url'};
	var type = base64.match(/^data:(.*);base64,/, function(){return RegExp.$1;})[1];
	var bin  = atob(base64.replace(/^.*,/, ''));
	var ary  = new Uint8Array(bin.length);
	for (var i = 0; i < bin.length; i++) {
		ary[i] = bin.charCodeAt(i);
	}
	var blob = new Blob([ary.buffer], {type:type});
	var url  = window.URL.createObjectURL(blob);
	if(opt.type == 'blob') return blob;
	return url;
}
10
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?