// Step 1: Create a Blob with "Hello World" content
const content = "Hello World";
const blob = new Blob([content], { type: 'text/plain' });
// Step 2: Create a URL for the Blob
const fileURL = URL.createObjectURL(blob);
// Step 3: Create an anchor element
const downloadLink = document.createElement('a');
// Step 4: Set the href to the Blob URL
downloadLink.href = fileURL;
// Step 5: Suggest a filename for the download
downloadLink.download = 'hello-world.txt';
// Step 6: Simulate a click on the anchor element
document.body.appendChild(downloadLink); // Append to the document
downloadLink.click(); // Trigger the download
// Step 7: Optionally, revoke the Blob URL
URL.revokeObjectURL(fileURL);
downloadLink.remove(); // Clean up
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.