8

I checked this same code in Firefox and it works perfectly. In fact, this worked in Chrome a few weeks back, but now I'm just getting a blank screen.

The code is below:

The function triggers on button click.

function saving() {
  var saveURL = canvas.toDataURL(); 
  window.open(saveURL, "_blank", "location=0, menubar=0");
}
Osama AbuSitta
  • 3,918
  • 4
  • 35
  • 51
Code geek
  • 91
  • 1
  • 5

2 Answers2

15

While it's no longer possible to do this in Chrome, there are workarounds, such as opening a blank document and writing to it.

var win = window.open();
win.document.write("<img src='"+canvas.toDataURL()+"'/>");
Braden Best
  • 8,830
  • 3
  • 31
  • 43
Savoo
  • 933
  • 7
  • 14
14

That's because of a recent change in Chrome:

https://developers.google.com/web/updates/2017/03/chrome-58-deprecations#remove_content-initiated_top_frame_navigations_to_data_urls

You cannot open data URLs directly anymore this way for security reasons.

Instead use the workaround proposed by @Savoo here in the other answer or use a download anchor and click it via JavaScript.

Sebastian
  • 7,729
  • 2
  • 37
  • 69