-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
66 lines (52 loc) · 2 KB
/
Copy pathscript.js
File metadata and controls
66 lines (52 loc) · 2 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
const generateButton = document.getElementById("generate-button");
const textInput = document.getElementById("text-input");
const linkInput = document.getElementById("link-input");
const qrCode = document.getElementById("qr-code");
generateButton.addEventListener("click", function() {
let input;
if(textInput.value) {
input = textInput.value;
} else if(linkInput.value) {
input = linkInput.value;
}
const qrUrl = "https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=" + input;
qrCode.src = qrUrl;
});
qrCode.addEventListener("click", function() {
if(linkInput.value) {
window.open(linkInput.value, '_blank');
}
});
const qrCodeContainer = document.getElementById("qr-code-container");
generateButton.addEventListener("click", function() {
// Code to generate QR code
qrCodeContainer.style.display = "block";
downloadButton.style.display = "block";
document.getElementById("qrcode").style.opacity = "1";
document.getElementById("download-button").style.opacity = "1";
document.getElementById("qrcode").classList.add("fade-in");
document.getElementById("download-button").classList.add("fade-in");
});
const downloadButton = document.getElementById('download-button');
// downloadButton.addEventListener('click', function() {
// // Get the QR code image
// const qrCode = document.getElementById('qr-code');
// // Create a new anchor element
// const link = document.createElement('a');
// // Set the anchor's href to the data URL of the QR code image
// link.href = qrCode.src;
// // Set the anchor's download attribute
// link.download = 'qr-code.png';
// // Click the anchor
// link.click();
// });
function downloadQRCode() {
// Get the QR code element
var qrcode = document.getElementById("qrcode");
var imgData = qrcode.src;
// Creates a link and triggers download
var link = document.createElement("a");
link.href = imgData;
link.download = "qrcode.png";
link.click();
}