How to detect if browser supports downloading a link that points to a data: URI scheme

68 Views Asked by At

I have an anchor tag that points to an encoded image and includes the download attribute. The goal is to allow the user to download the data URI (image) to disk simply by clicking on the link.

Example:

<a download="foo" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGElEQVQYlWNkYGD4z0AEYCJG0ahC6ikEAKYXAROlAhdFAAAAAElFTkSuQmCC">
Download image
</a>

There are two things going on here that I need to check for browser support:

  1. Whether or not the browser supports the download attribute
  2. Whether or not the browser supports the href=data:

The way I check for support for the download attribute is:

document.createElement('a').download === undefined;

However, I don't know how to detect if the browser supports the download if/when the href points to an url that uses the data: URI scheme.

I know that MS Edge doesn't support the example code above (fiddle here).. so I'm sure that there are other modern browsers that don't support it either. - And I don't want to check for the browser type (eg. if the navigator.userAgent contains 'Edge').

0

There are 0 best solutions below