-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQR-Code-Generator.html
More file actions
125 lines (107 loc) · 2.82 KB
/
Copy pathQR-Code-Generator.html
File metadata and controls
125 lines (107 loc) · 2.82 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>QR Code Generator</title>
<link rel="icon" href="favicon.png">
<style>
body {
font-family: Arial, sans-serif;
background: #eef8ff;
margin: 0;
padding: 20px;
text-align: center;
}
.container {
max-width: 400px;
margin: auto;
background: #fff;
padding: 25px;
border-radius: 12px;
box-shadow: 0 4px 12px rgba(0, 123, 255, 0.15);
}
h2 {
color: #007bff;
}
input[type="text"] {
width: 100%;
padding: 10px;
font-size: 16px;
margin-top: 10px;
border: 1px solid #ccc;
border-radius: 10px;
}
button {
margin-top: 15px;
padding: 10px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 8px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: #0056b3;
}
#qrcode {
margin-top: 20px;
display: flex;
justify-content: center;
}
#downloadBtn {
display: none;
margin-top: 15px;
background-color: #28a745;
}
#downloadBtn:hover {
background-color: #1e7e34;
}
</style>
</head>
<body>
<div class="container">
<h2>QR Code Generator</h2>
<input type="text" id="qrText" placeholder="Enter text or URL" />
<button onclick="generateQR()">Generate QR</button>
<div id="qrcode"></div>
<button id="downloadBtn" onclick="downloadQR()">Download QR</button>
</div>
<!-- QRCode.js CDN -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>
<script>
let qr;
function generateQR() {
const text = document.getElementById("qrText").value.trim();
const qrContainer = document.getElementById("qrcode");
const downloadBtn = document.getElementById("downloadBtn");
qrContainer.innerHTML = "";
downloadBtn.style.display = "none";
if (text === "") {
alert("Please enter some text.");
return;
}
qr = new QRCode(qrContainer, {
text: text,
width: 200,
height: 200,
colorDark: "#000000",
colorLight: "#ffffff",
correctLevel: QRCode.CorrectLevel.H
});
setTimeout(() => {
downloadBtn.style.display = "inline-block";
}, 500); // wait to ensure canvas is rendered
}
function downloadQR() {
const img = document.querySelector("#qrcode img") || document.querySelector("#qrcode canvas");
if (!img) return;
const link = document.createElement("a");
link.href = img.src || img.toDataURL("image/png");
link.download = "qr-code.png";
link.click();
}
</script>
</body>
</html>