

WORDPRESS
Force Download with JavaScript
Force download scripts have been an important part of internet usability for a long time. I can attest to that by the number of times I’ve implemented this feature on the server side and the popularity of my PHP Force Download post, even to this day. With the web world having moved much more the client side, I started looking for a method to force download without the need of a server, and I found it….right in the Firefox DevTools Debugger!
The JavaScript
The function to do this is quite small and relies on URL.createObjectUrl
:
function downloadFile(data, fileName, type="text/plain") { // Create an invisible A element const a = document.createElement("a"); a.style.display = "none"; document.body.appendChild(a); // Set the HREF to a Blob representation of the data to be downloaded a.href = window.URL.createObjectURL( new Blob([data], { type }) ); // Use download attribute to set set desired file name a.setAttribute("download", fileName); // Trigger the download by simulating click a.click(); // Cleanup window.URL.revokeObjectURL(a.href); document.body.removeChild(a);
Function of Force Download with JavaScript
The function injects an <a>
element into the body, sets it URL to a Blob
value to the text content of the destination file, and clicks the element to trigger the download. The element remains hidden during the process and is removed from the DOM immediately after the click()
call. As soon as the function is called, the browser’s download prompt is displayed.

-
HOW TO2 months ago
How To Get Unlimited Free Airtel Data Via My Airtel App 2020
-
GAMES6 months ago
Download FIFA PC Game Windows For Free Download
-
TECHNOLOGY7 months ago
Download PUBG Mobile KR for PC – Installation On Windows & MAC
-
GAMES3 months ago
Download PUBG MOBILE (KR) 2021 APK For PC For Free
-
Uncategorized3 days ago
PES 2021 FULL EFL Championship Stadium Pack 2020-2021
-
GAMES4 months ago
Download PES 2017 Patch PES 2021 V1.0 PC Game
-
TECHNOLOGY6 months ago
What Is Cache App?
-
APPS2 months ago
Download Mi Mover For PC -Windows 7,8 & 10 [ Latest Updated 2020]