0

I'm writing a web app that generates images which the user can then save. The image is created as a data URL and I'm opening it by writing to the result of window.open() as illustrated in this jsfiddle. However, after the function runs the image can't be saved just by choosing "Save image as..." from the right-click menu. Instead, the user has to choose "Open image in new tab", right-click the image in that tab, and then select "Save image as..." from that menu, which is a rather clunky user experience.

How can I open the image from the function in the same way that the "Open image in new tab" option in the menu does? This is the function I'm using to open images:

let button = document.getElementById("image-button");
button.onclick = function () {
let win = window.open();
  win.document.write('<img src="' + dataUrl + '"/>');
};

This is the image I'm using:

.

devneal17
  • 281
  • 1
  • 4
  • 14

0 Answers0