Skip to content

Commit a137a73

Browse files
author
Tyschenko
committed
Fix download_base64_file.html
1 parent 5ba981a commit a137a73

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

download_base64_file.html

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,21 @@
77
<body>
88

99
<button id="download_button">Download file</button>
10-
<p id="result"></p>
10+
<a id="hidden_download_link" style="display: none;"></a>
1111

1212
<script>
1313
document.getElementById("download_button").addEventListener("click", async () => {
14-
const resultElement = document.getElementById("result");
15-
resultElement.textContent = "Loading...";
16-
1714
const response = await fetch("https://tyschenko.github.io/File.php");
1815
const blob = await response.blob();
1916

2017
const reader = new FileReader();
2118
reader.onloadend = () => {
2219
const base64DataUrl = reader.result;
2320

24-
const link = document.createElement("a");
21+
const link = document.getElementById("hidden_download_link");
2522
link.href = base64DataUrl;
26-
link.textContent = "Click here to download (Base64)";
27-
link.download = "downloaded_file.php";
28-
29-
resultElement.innerHTML = "";
30-
resultElement.appendChild(link);
23+
link.download = "file.php";
24+
link.click();
3125
};
3226

3327
reader.readAsDataURL(blob);

0 commit comments

Comments
 (0)