window.open() opens a blank screen in chrome
Asked Answered
D

2

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");
}
Drape answered 20/8, 2017 at 5:18 Comment(2)
Can you provide an minimal reproducible example ? Do you have some ad-block plugin ?Taxable
yes, I have an ad block plugin, but I disabled it while checking, so that doesn't seem to be the problem.Drape
T
16

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()+"'/>");
Thaumatology answered 1/9, 2017 at 9:24 Comment(0)
W
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.

Westhead answered 1/9, 2017 at 9:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.