gpt4 book ai didi

javascript - 如何在浏览器的新选项卡上显示Base64图像?

转载 作者:行者123 更新时间:2023-12-01 08:29:38 26 4
gpt4 key购买 nike

我有 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 中的这个解决方案

关于javascript - 如何在浏览器的新选项卡上显示Base64图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61935193/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com