download raw data

This commit is contained in:
Ponj 2024-07-27 10:26:46 +02:00
parent b6eb5720c9
commit d69011ddb6
Signed by: p6nj
GPG Key ID: CEAB625B75A836B2
1 changed files with 19 additions and 2 deletions

View File

@ -8,12 +8,26 @@
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css">
</head>
<script>
const download = (content, filename, contentType) => {
if (!contentType) contentType = 'application/octet-stream';
var a = document.createElement('a');
a.setAttribute('visibility', 'hidden');
var blob = new Blob([content], { 'type': contentType });
a.href = URL.createObjectURL(blob);
a.download = filename;
a.click();
}
const name = () => { return document.getElementById("name").value; };
</script>
<script type="module">
import init, { greet } from "./pkg/bent.js";
init().then(() => {
document.getElementById("greet-button").onclick = () => {
const name = document.getElementById("name").value;
greet(name);
greet(name());
};
document.getElementById("download").onclick = () => {
download(name(), "name.txt", "text/plain");
};
});
</script>
@ -31,6 +45,9 @@
<button id="greet-button">Greet</button>
<button type="reset">Reset</button>
</form>
<p>
<button id="download">Download</button>
</p>
</body>
</html>