window.open() opens a blank screen in chrome

2019-05-11 12:42发布

问题:

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");
}

回答1:

          var win=window.open();
          win.document.write("<img src='"+canvas.toDataURL()+"'/>");


回答2:

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.