

Using the function to download: downloadFile('('), Create an element to download the string.Convert the blob object to a string by using URL.createObjectURL().Use fetch API to download the script file.So the steps for downloading the file will be: If we use fetch to request the data, the response can be converted to blob type. Using Blob to download fileīlob stands for Binary Large Object and is a data type that can store binary data. If the file is not of the same origin, the browser will open it rather than downloading it.įortunately, the download attribute supports the blob: scheme. download the google analytics javascript file with aīut it does not work, because download only works for same-origin URLs. It’s easy to download a file with tag, just remember to add a download attribute to tell the browser to download rather than opening the hyperlink. Using tag with download attribute (Not working) In order to demonstrate the download function, this article takes downloading the Google Analytics JavaScript file as an example. But the simpler you think, the more problems you will encounter in the implementation process. I remember downloading a file was very simple, basically the same as opening a link in a new tab. Recently I developed a feature that needs to add a download button to the page to support downloading a PDF file hosted on a CDN.
