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 tag ī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. Lists Unordered Lists Ordered Lists Other Lists HTML Block & Inline HTML Classes HTML Id HTML Iframes HTML JavaScript HTML File Paths HTML Head HTML Layout HTML Responsive HTML Computercode HTML Semantics HTML Style Guide HTML Entities HTML Symbols HTML Emojis HTML Charset HTML URL Encode HTML vs.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.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |