40 lines
1.3 KiB
HTML
40 lines
1.3 KiB
HTML
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<meta charset="UTF-8">
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
<title>File Download App</title>
|
||
|
</head>
|
||
|
<body>
|
||
|
|
||
|
<button id="downloadButton">Download File</button>
|
||
|
|
||
|
<script>
|
||
|
// Function to trigger the download
|
||
|
function downloadFile() {
|
||
|
// Create a Blob containing the file data
|
||
|
var fileData = "Hello, this is the content of the file!"; // this will end up being the concatenated .pgn results returned by the async function
|
||
|
var blob = new Blob([fileData], { type: "text/plain" });
|
||
|
|
||
|
// Create an anchor element and set its attributes
|
||
|
var a = document.createElement("a");
|
||
|
a.href = window.URL.createObjectURL(blob);
|
||
|
a.download = "example.txt";
|
||
|
|
||
|
// Append the anchor element to the body
|
||
|
document.body.appendChild(a);
|
||
|
|
||
|
// Programmatically click the anchor to trigger the download
|
||
|
a.click();
|
||
|
|
||
|
// Remove the anchor from the body
|
||
|
document.body.removeChild(a);
|
||
|
}
|
||
|
|
||
|
// Attach the downloadFile function to the button click event
|
||
|
document.getElementById("downloadButton").addEventListener("click", downloadFile);
|
||
|
</script>
|
||
|
|
||
|
</body>
|
||
|
</html>
|