如何在浏览器的新标签页显示Base64图片?

How to show Base64 image on browser's new tab?

我有 Base64 编码的图像作为响应,如何使用 js 在浏览器的新选项卡中显示该图像?任何人都可以提出解决方案。谢谢

 success: function (base64Image) {


         }

假设您要获取 GIF 图片:


// Display a base64 URL inside an iframe in another window.
function debugBase64(base64URL){
    var win = window.open();
    win.document.write('<iframe src="' + base64URL  + '" frameborder="0" style="border:0; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%;" allowfullscreen></iframe>');
}

success: function (base64Image) {

    // e.g This will open an image in a new window
    debugBase64("data:image/gif;base64," + base64Image);

    // you can try with this base64 (it is a red dot)
    // debugBase64("data:image/gif;base64,R0lGODdhAQABAPAAAP8AAAAAACwAAAAAAQABAAACAkQBADs=");

}

否则只需将 data:image/gif; 更改为您需要的正确 MIME 类型即可。

您可以在此处找到完整列表https://www.freeformatter.com/mime-types-list.html

我从 https://ourcodeworld.com/articles/read/682/what-does-the-not-allowed-to-navigate-top-frame-to-data-url-javascript-exception-means-in-google-chrome

找到并尝试了这个解决方案