1

There is a feature in the app I'm working on that allows a user to open an image in a new window. It's implemented the following way:

const link = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAA...';
window.open(link)

It works perfectly fine in firefox, but when I do that in chrome it redirects me to an empty page with about:blank url? How do I fix that behaviour?

Umbrella
  • 1,085
  • 1
  • 14
  • 30

2 Answers2

3

You can achieve this in Chrome by adding a img tag to the new window:

const link = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAA...';
var newWindow = window.open();
newWindow.document.write('<img src="' + link + '" />');
Huso
  • 1,501
  • 9
  • 14
2

I think that Chrome has deprecated the opening of links with a "data:" URL. See this link from Google for explanation and this answer from a similar stack overflow question for a workaround solution. Hope this helps!

melmquist
  • 440
  • 1
  • 4
  • 12