Open image created with JS on new tab

Viewed 41

Let's say I have an image that I have previously created using JS (e.g. a base64 of a canvas) and I want to open it to a new page.. I've tried the following:

const src = "base 64 of the image";
window.open(src,'Image','width=largeImage.stylewidth,height=largeImage.style.height,resizable=1');

this is now working (at least on the latest stable Chrome version).. am I missing something?

1 Answers

Try this:

    var image = new Image();
    image.src = "data:image/jpg;base64, " + "base 64 of the image";

    var w = window.open("");
    w.document.write(image.outerHTML);
    w.document.close();

Also, make sure to specify the correct content type, in my answer I'm using jpg

Related