This repository has been archived by the owner on Apr 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.js
54 lines (46 loc) · 1.6 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//start code
//31-July-2020
//Al Nahian | https://alnahian.xyz
let qrData = document.getElementById("qr-data"),
qrcode = new QRCode(document.getElementById("qrcode"), {
text: "Al Nahian",
width: 200,
height: 200,
colorDark: "#8880ff",
colorLight: "#ffffff",
correctLevel: QRCode.CorrectLevel.H
}),
generateButton = document.getElementById("generate-button");
generateButton.addEventListener("click", function (e) {
e.preventDefault();
let data = qrData.value;
qrcode.makeCode(data);
if (data == "") {
alert("You Cannot Leave Fields Empty!");
}
});
//Downloading QR Code
let downloadButton = document.getElementById("download-button"),
qrCanvas = document.querySelector("canvas"),
generatedQrCode = document.querySelector("img");
downloadButton.addEventListener("click", function (e) {
e.preventDefault();
let data = qrData.value;
if (data == "") {
alert("Please Generate a QR Code To Download !");
} else {
const dataURI = qrCanvas.toDataURL("image / png");
generatedQrCode.src = dataURI;
// For Microsoft Edge or Old Browser Only
if (window.navigator.msSaveBlob) {
window.navigator.msSaveBlob(qrCanvas.msToBlob(), "qr-code.png")
} else {
const a = document.createElement("a");
document.body.appendChild(a);
a.href = qrCanvas.toDataURL();
a.download = "qr-code.png";
a.click();
document.body.removeChild(a);
}
}
});