forked from LalithKumar77/QRGen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
49 lines (47 loc) · 1.85 KB
/
index.html
File metadata and controls
49 lines (47 loc) · 1.85 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
<!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="./Logo.jpeg">
<link rel="stylesheet" type="text/css" href="./styles.css">
</head>
<body>
<div id="Pr-name"><h1>QR Code Generator</h1></div>
<form action="/submit" method="post">
<input type="text" name="text" placeholder="Enter text to generate QR code" required>
<input id="btn" type="submit" value="Generate QR Code">
</form>
<div id="qr-code-container" style="display: none;">
<img id="qr-code" src="" alt="QR Code">
<a id="download-link" style="display: none;">Download QR Code</a>
</div>
<script>
const form = document.querySelector('form');
form.addEventListener('submit', (e) => {
e.preventDefault();
const text = document.querySelector('input[name="text"]').value;
fetch('/submit', {
method: 'POST',
body: new URLSearchParams({ text }),
})
.then((response) => response.arrayBuffer())
.then((arrayBuffer) => {
const blob = new Blob([arrayBuffer], { type: 'image/png' });
const url = URL.createObjectURL(blob);
const img = document.querySelector('#qr-code');
img.src = url;
document.querySelector('#qr-code-container').style.display = 'block';
const a = document.querySelector('#download-link');
a.href = url;
a.download = 'qr_code.png';
a.style.display = 'block';
})
.catch((error) => {
console.error('Error generating QR code:', error);
});
});
</script>
</body>
</html>