在新标签页打开用 JS 创建的图片

Open image created with JS on new tab

假设我有一张我之前使用 JS 创建的图像(例如 canvas 的 base64),我想将它打开到一个新页面。我尝试了以下操作:

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

现在可以正常工作了(至少在最新的稳定 Chrome 版本上是这样)。我是不是漏掉了什么?

试试这个:

    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();

此外,请确保指定正确的内容类型,在我的回答中我使用的是 jpg