Skip to content

Commit

Permalink
download QR
Browse files Browse the repository at this point in the history
  • Loading branch information
justinh-rahb committed Oct 20, 2023
1 parent e126733 commit 0ebeb08
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,6 @@ <h1><i class="fas fa-qrcode"></i><i class="fas fa-cog"></i></h1>
</form>
<div id="qrcode" class="my-5 d-flex justify-content-center"></div>
</div>
<script src="static/generator.js?v=202310192002"></script>
<script src="static/generator.js?v=202310192012"></script>
</body>
</html>
19 changes: 17 additions & 2 deletions static/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,24 @@ function generateQRCode() {
}

$('#qrcode').empty();
$('#qrcode').qrcode({
const qrCodeCanvas = $('#qrcode').qrcode({
text: data
});
})[0].firstChild;

// Convert the canvas to a PNG data URL
const imageData = qrCodeCanvas.toDataURL("image/png");

// Create a unique filename based on the timestamp
const filename = `QRCode_${new Date().toISOString().replace(/[-:.]/g, "")}.png`;

// Create an anchor element and set its attributes
const anchor = document.createElement("a");
anchor.href = imageData;
anchor.download = filename;
anchor.innerHTML = "<img src='" + imageData + "' alt='QR Code'/>";

// Clear the QR code container and append the clickable anchor
$('#qrcode').empty().append(anchor);
}

document.addEventListener("DOMContentLoaded", function() {
Expand Down

0 comments on commit 0ebeb08

Please sign in to comment.