TypeError: BlobBuilder is not a constructor
var BlobBuilder = window.BlobBuilder || window.MozBlobBuilder || window.WebKitBlobBuilder || window.MSBlobBuilder; var bb = new BlobBuilder(); bb.append(arr.stString());
今天在chrome浏览器中这样使用时,出线错误TypeError: BlobBuilder is not a constructor。
解决:
原文地址:http://stackoverflow.com/questions/15293694/blob-constructor-browser-compatibility
0 down vote accepted Got it working with your code. I only had to change some little detail: if(e.name == 'TypeError' && window.BlobBuilder){ var bb = new BlobBuilder(); bb.append(data); out = bb.getBlob(datatype); console.debug("case 2"); } bb.append(data); // data must be with no brackets My function(constructor) that works now for all browsers: var NewBlob = function(data, datatype) { var out; try { out = new Blob([data], {type: datatype}); console.debug("case 1"); } catch (e) { window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder; if (e.name == 'TypeError' && window.BlobBuilder) { var bb = new BlobBuilder(); bb.append(data); out = bb.getBlob(datatype); console.debug("case 2"); } else if (e.name == "InvalidStateError") { // InvalidStateError (tested on FF13 WinXP) out = new Blob([data], {type: datatype}); console.debug("case 3"); } else { // We're screwed, blob constructor unsupported entirely console.debug("Errore"); } } return out; }
posted on 2016-09-23 19:27 ZhYQ_note 阅读(2411) 评论(0) 编辑 收藏 举报