且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Chrome iOS上打开Blob网址

更新时间:2023-01-04 22:32:08

FileReader解决了我的问题。

  var reader = new FileReader(); 
var out = new Blob([this.response],{type:'application / pdf'});
reader.onload = function(e){
window.location.href = reader.result ;
}
reader.readAsDataURL(out);


I'd like to open Blob object in a browser window.

This code works everywhere but iOS Chrome (and IE of course but I can solve IE). The window is not redirected to the url (which is correct or at least the same as in other browsers). Is there any known workaround for Chrome iOS?

var blob = new window.Blob(['Hello, world!'], {type: 'text/plain;charset=utf-8'});
window.URL = window.URL || window.webkitURL;
var url = window.URL.createObjectURL(blob);
window.location.href = url;

I've tried <a href="{blobUrl}> instead of window.location.href but it doesn't work either.

FileReader solved my problem.

var reader = new FileReader();
var out = new Blob([this.response], {type: 'application/pdf'});
reader.onload = function(e){
  window.location.href = reader.result;
}
reader.readAsDataURL(out);