0

我正在创建一个 BLOB url 并将这个 url 分配给 iframe 的位置。在 Firefox 和 Chrome 中,这没有问题,在 IE10 中,BLOB url 的内容不会显示在 iframe 中。在 IE10 调试器中,我可以看到,BLOB url 的创建没有问题。

var test =
{
   init: function()
   {
      var parts = ["<html><body>test</body></html>"];
      var myBlob = new Blob(parts, {"type":"text\html"}); 
      var blobUrl = URL.createObjectURL(myBlob);

      document.getElementById("test").contentWindow.location = blobUrl;
   }
}

window.addEventListener("DOMContentLoaded", test.init, true);

知道有什么问题吗?

4

1 回答 1

0

请尝试对每个 BlobBuilder 和 Blob 构造函数使用特征检测。

if (typeof Blob !== "undefined") {
   // use the Blob constructor
} else if (window.MSBlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder) {
   // use the supported vendor-prefixed BlobBuilder
} else {
   // neither Blob constructor nor BlobBuilder is supported
}

另一个技巧是使用URL.createObjectURL(blob)相对于window

var blobUrl = window.URL.createObjectURL(myBlob);

IE对此很明智!也许这有帮助!

于 2013-01-03T11:54:02.050 回答