{"id":2103,"date":"2022-07-06T14:57:47","date_gmt":"2022-07-06T09:57:47","guid":{"rendered":"https:\/\/www.edopedia.com\/blog\/?p=2103"},"modified":"2022-07-06T15:40:36","modified_gmt":"2022-07-06T10:40:36","slug":"build-file-downloader-from-url-using-javascript-html5-css3","status":"publish","type":"post","link":"https:\/\/www.edopedia.com\/blog\/build-file-downloader-from-url-using-javascript-html5-css3\/","title":{"rendered":"Build File Downloader From URL Using JavaScript HTML5 CSS3"},"content":{"rendered":"\n<p>Free JavaScript file download from URL script.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">index.html<\/h2>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;htmlmixed&quot;,&quot;mime&quot;:&quot;text\/html&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;HTML&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;html&quot;}\">&lt;!DOCTYPE html&gt;\n&lt;html lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;\n  &lt;head&gt;\n    &lt;meta charset=&quot;utf-8&quot;&gt;\n    &lt;title&gt;File Downloader in JavaScript | Edopedia.com&lt;\/title&gt;\n    &lt;style&gt;\n        \/* Import Google Font - Poppins *\/\n@import url('https:\/\/fonts.googleapis.com\/css2?family=Poppins:wght@400;500;600;700&amp;display=swap');\n*{\n  margin: 0;\n  padding: 0;\n  box-sizing: border-box;\n  font-family: 'Poppins', sans-serif;\n}\nbody{\n  display: flex;\n  padding: 0 10px;\n  align-items: center;\n  justify-content: center;\n  min-height: 100vh;\n  background: #4285F4;\n}\n.wrapper{\n  max-width: 500px;\n  background: #fff;\n  border-radius: 7px;\n  padding: 20px 25px 15px;\n  box-shadow: 0 15px 40px rgba(0,0,0,0.12);\n}\nheader h1{\n  font-size: 27px;\n  font-weight: 500;\n}\nheader p{\n  margin-top: 5px;\n  font-size: 18px;\n  color: #474747;\n}\nform{\n  margin: 20px 0 27px;\n}\nform input{\n  width: 100%;\n  height: 60px;\n  outline: none;\n  padding: 0 17px;\n  font-size: 19px;\n  border-radius: 5px;\n  border: 1px solid #b3b2b2;\n  transition: 0.1s ease;\n}\nform input::placeholder{\n  color: #b3b2b2;\n}\nform input:focus{\n  box-shadow: 0 3px 6px rgba(0,0,0,0.13);\n}\nform button{\n  width: 100%;\n  border: none;\n  opacity: 0.7;\n  outline: none;\n  color: #fff;\n  cursor: pointer;\n  font-size: 17px;\n  margin-top: 20px;\n  padding: 15px 0;\n  border-radius: 5px;\n  pointer-events: none;\n  background: #4285F4;\n  transition: opacity 0.15s ease;\n}\nform input:valid ~ button{\n  opacity: 1;\n  pointer-events: auto;\n}\n    &lt;\/style&gt;\n    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;\n  &lt;\/head&gt;\n  &lt;body&gt;\n    &lt;div class=&quot;wrapper&quot;&gt;\n      &lt;header&gt;\n        &lt;h1&gt;File Downloader&lt;\/h1&gt;\n        &lt;p&gt;Paste url of image, video, or pdf to download. This tool is made with vanilla javascript.&lt;\/p&gt;\n      &lt;\/header&gt;\n      &lt;form action=&quot;#&quot;&gt;\n        &lt;input type=&quot;url&quot; placeholder=&quot;Paste file url&quot; required&gt;\n        &lt;button&gt;Download File&lt;\/button&gt;\n      &lt;\/form&gt;\n    &lt;\/div&gt;\n    &lt;script&gt;\n        const fileInput = document.querySelector(&quot;input&quot;),\ndownloadBtn = document.querySelector(&quot;button&quot;);\ndownloadBtn.addEventListener(&quot;click&quot;, e =&gt; {\n    e.preventDefault();\n    downloadBtn.innerText = &quot;Downloading file...&quot;;\n    fetchFile(fileInput.value);\n});\nfunction fetchFile(url) {\n    fetch(url).then(res =&gt; res.blob()).then(file =&gt; {\n        let tempUrl = URL.createObjectURL(file);\n        const aTag = document.createElement(&quot;a&quot;);\n        aTag.href = tempUrl;\n        aTag.download = url.replace(\/^.*[\\\\\\\/]\/, '');\n        document.body.appendChild(aTag);\n        aTag.click();\n        downloadBtn.innerText = &quot;Download File&quot;;\n        URL.revokeObjectURL(tempUrl);\n        aTag.remove();\n    }).catch(() =&gt; {\n        alert(&quot;Failed to download file!&quot;);\n        downloadBtn.innerText = &quot;Download File&quot;;\n    });\n}\n        &lt;\/script&gt;\n  &lt;\/body&gt;\n&lt;\/html&gt;<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Free JavaScript file download from URL script. index.html<\/p>\n","protected":false},"author":1,"featured_media":2105,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[112],"tags":[],"class_list":["post-2103","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Build File Downloader From URL Using JavaScript HTML5 CSS3<\/title>\n<meta name=\"description\" content=\"Free JavaScript file download from URL script. index.html &lt;!DOCTYPE html&gt; &lt;html lang=&quot;en&quot; dir=&quot;ltr&quot;&gt; &lt;head&gt; &lt;meta\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.edopedia.com\/blog\/build-file-downloader-from-url-using-javascript-html5-css3\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Build File Downloader From URL Using JavaScript HTML5 CSS3\" \/>\n<meta property=\"og:description\" content=\"Free JavaScript file download from URL script. index.html &lt;!DOCTYPE html&gt; &lt;html lang=&quot;en&quot; dir=&quot;ltr&quot;&gt; &lt;head&gt; &lt;meta\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.edopedia.com\/blog\/build-file-downloader-from-url-using-javascript-html5-css3\/\" \/>\n<meta property=\"og:site_name\" content=\"Edopedia\" \/>\n<meta property=\"article:author\" content=\"trulyfurqan\" \/>\n<meta property=\"article:published_time\" content=\"2022-07-06T09:57:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-06T10:40:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/07\/file_downloader_from_url_js.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"880\" \/>\n\t<meta property=\"og:image:height\" content=\"495\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Furqan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Furqan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Build File Downloader From URL Using JavaScript HTML5 CSS3","description":"Free JavaScript file download from URL script. index.html &lt;!DOCTYPE html&gt; &lt;html lang=&quot;en&quot; dir=&quot;ltr&quot;&gt; &lt;head&gt; &lt;meta","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.edopedia.com\/blog\/build-file-downloader-from-url-using-javascript-html5-css3\/","og_locale":"en_US","og_type":"article","og_title":"Build File Downloader From URL Using JavaScript HTML5 CSS3","og_description":"Free JavaScript file download from URL script. index.html &lt;!DOCTYPE html&gt; &lt;html lang=&quot;en&quot; dir=&quot;ltr&quot;&gt; &lt;head&gt; &lt;meta","og_url":"https:\/\/www.edopedia.com\/blog\/build-file-downloader-from-url-using-javascript-html5-css3\/","og_site_name":"Edopedia","article_author":"trulyfurqan","article_published_time":"2022-07-06T09:57:47+00:00","article_modified_time":"2022-07-06T10:40:36+00:00","og_image":[{"width":880,"height":495,"url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/07\/file_downloader_from_url_js.jpg","type":"image\/jpeg"}],"author":"Furqan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Furqan","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.edopedia.com\/blog\/build-file-downloader-from-url-using-javascript-html5-css3\/#article","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/build-file-downloader-from-url-using-javascript-html5-css3\/"},"author":{"name":"Furqan","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339"},"headline":"Build File Downloader From URL Using JavaScript HTML5 CSS3","datePublished":"2022-07-06T09:57:47+00:00","dateModified":"2022-07-06T10:40:36+00:00","mainEntityOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/build-file-downloader-from-url-using-javascript-html5-css3\/"},"wordCount":18,"commentCount":0,"publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/build-file-downloader-from-url-using-javascript-html5-css3\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/07\/file_downloader_from_url_js.jpg","articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.edopedia.com\/blog\/build-file-downloader-from-url-using-javascript-html5-css3\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.edopedia.com\/blog\/build-file-downloader-from-url-using-javascript-html5-css3\/","url":"https:\/\/www.edopedia.com\/blog\/build-file-downloader-from-url-using-javascript-html5-css3\/","name":"Build File Downloader From URL Using JavaScript HTML5 CSS3","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/build-file-downloader-from-url-using-javascript-html5-css3\/#primaryimage"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/build-file-downloader-from-url-using-javascript-html5-css3\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/07\/file_downloader_from_url_js.jpg","datePublished":"2022-07-06T09:57:47+00:00","dateModified":"2022-07-06T10:40:36+00:00","description":"Free JavaScript file download from URL script. index.html &lt;!DOCTYPE html&gt; &lt;html lang=&quot;en&quot; dir=&quot;ltr&quot;&gt; &lt;head&gt; &lt;meta","breadcrumb":{"@id":"https:\/\/www.edopedia.com\/blog\/build-file-downloader-from-url-using-javascript-html5-css3\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.edopedia.com\/blog\/build-file-downloader-from-url-using-javascript-html5-css3\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/build-file-downloader-from-url-using-javascript-html5-css3\/#primaryimage","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/07\/file_downloader_from_url_js.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/07\/file_downloader_from_url_js.jpg","width":880,"height":495,"caption":"Build File Downloader From URL Using JavaScript HTML5 CSS3"},{"@type":"BreadcrumbList","@id":"https:\/\/www.edopedia.com\/blog\/build-file-downloader-from-url-using-javascript-html5-css3\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.edopedia.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Build File Downloader From URL Using JavaScript HTML5 CSS3"}]},{"@type":"WebSite","@id":"https:\/\/www.edopedia.com\/blog\/#website","url":"https:\/\/www.edopedia.com\/blog\/","name":"Edopedia","description":"Coding\/Programming Blog","publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.edopedia.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.edopedia.com\/blog\/#organization","name":"Edopedia","url":"https:\/\/www.edopedia.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","width":400,"height":100,"caption":"Edopedia"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339","name":"Furqan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","caption":"Furqan"},"description":"Well. I've been working for the past three years as a web designer and developer. I have successfully created websites for small to medium sized companies as part of my freelance career. During that time I've also completed my bachelor's in Information Technology.","sameAs":["http:\/\/www.edopedia.com\/blog\/","trulyfurqan"],"url":"https:\/\/www.edopedia.com\/blog\/author\/furqan\/"}]}},"_links":{"self":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/2103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/comments?post=2103"}],"version-history":[{"count":0,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/2103\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media\/2105"}],"wp:attachment":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media?parent=2103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/categories?post=2103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/tags?post=2103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}