

For this, we need to use the fetch API in combination with the URL.createObjectURL to create the correct URL for the blob, then use this for the href. To review, open the file in an editor that reveals hidden Unicode characters.

Using blobs is a more generic approach to download binary files, or files that are not programmatically generated, but hosted elsewhere. download-embedded-vimeo-video.js This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. In order to come around this, introduce you to blobs. It doesn't work with non-text-based files, and while we could change the MIME type, it also doesn't work with files hosted elsewhere.

After the download of the resource has been started, we can remove the link from the document using the removeChild method. We also want to set its display property to none, in order to prevent the link from showing up anywhere on the page.Īfter all necessary attributes are present on the link, we can append the element to the document, using the appendChild method, and trigger a click on the link to initiate the download. When the link is created, we can set the appropriate attributes on it using the setAttribute method. It can also optionally accept a filename as the second parameter. This function accepts a JavaScript object that will be converted into JSON.
