JSFiddle - React, Tailwind, and code Playground
by Xevion
HTML
<h1>Z</h1>
<p>Z</p>
<button onclick="download(x'.txt', 'Hello world!');" type="button" class="btn btn-lg btn-success btn-block">Download</button></body>
JavaScript
var x = Math.floor((Math.random() * 1000) + 1);function download(filename, text) {
var pom = document.createElement('a');
pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
pom.setAttribute('download', filename);
if (document.createEvent) {
var event = document.createEvent('MouseEvents');
event.initEvent('click', true, true);
pom.dispatchEvent(event);
}
else {
pom.click();
}