Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have Base64 encoded image as response, how can I show that image in new tab of browser using js? anybody can suggest a solutions. Thanks

 success: function (base64Image) {


         }
like image 662
Asif Avatar asked Oct 27 '25 10:10

Asif


1 Answers

Supposing you are going to get a GIF image:


// 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=");

}

Otherwise just change data:image/gif; with the right MIME type you need.

You can find a complete list here https://www.freeformatter.com/mime-types-list.html

I found and I just tried this solution from https://ourcodeworld.com/articles/read/682/what-does-the-not-allowed-to-navigate-top-frame-to-data-url-javascript-exception-means-in-google-chrome

like image 178
Francesco Orsi Avatar answered Oct 29 '25 23:10

Francesco Orsi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!