代码之家  ›  专栏  ›  技术社区  ›  Гарик Мкртчян

Chrome浏览器无法打开文件

  •  0
  • Гарик Мкртчян  · 技术社区  · 9 年前

    window.open('data:' + type + ';base64,' + data, '_blank', 'height=300,width=400');
    

    我从服务器获取的类型和数据。

    因此,它在Opera、Mozilla和Edge中都能完美地工作。 Popup in opera 但在Chrome中,我得到了一个空的弹出窗口。 Popup in chrome

    2 回复  |  直到 9 年前
        1
  •  2
  •   Гарик Мкртчян    9 年前

    使用而不是此

    window.open('data:' + type + ';base64,' + data, '_blank', 'height=300,width=400');
    

    此代码

    let byteCharacters = atob(file);
    let byteNumbers = new Array(byteCharacters.length);
    for (let i = 0; i < byteCharacters.length; i++) {
         byteNumbers[i] = byteCharacters.charCodeAt(i);
    }
    let byteArray = new Uint8Array(byteNumbers);
    let blob = new Blob([byteArray], {type: contentType});
    
    const fileURL = URL.createObjectURL(blob);
    window.open(fileURL, '_blank', 'height=300,width=400');
    

        2
  •  0
  •   Some1Else    9 年前

    原因可能是chrome的硬件加速。 尝试按照Douglas的答案禁用它, here .

    推荐文章