download raw data
This commit is contained in:
parent
b6eb5720c9
commit
d69011ddb6
1 changed files with 19 additions and 2 deletions
|
@ -8,12 +8,26 @@
|
||||||
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css">
|
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css">
|
||||||
</head>
|
</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">
|
<script type="module">
|
||||||
import init, { greet } from "./pkg/bent.js";
|
import init, { greet } from "./pkg/bent.js";
|
||||||
init().then(() => {
|
init().then(() => {
|
||||||
document.getElementById("greet-button").onclick = () => {
|
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>
|
</script>
|
||||||
|
@ -31,6 +45,9 @@
|
||||||
<button id="greet-button">Greet</button>
|
<button id="greet-button">Greet</button>
|
||||||
<button type="reset">Reset</button>
|
<button type="reset">Reset</button>
|
||||||
</form>
|
</form>
|
||||||
|
<p>
|
||||||
|
<button id="download">Download</button>
|
||||||
|
</p>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
Loading…
Reference in a new issue