-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
32 lines (31 loc) · 1.22 KB
/
script.js
File metadata and controls
32 lines (31 loc) · 1.22 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
document.getElementById("btn").addEventListener("click", function () {
document.getElementById("display").src = "https://api.qrserver.com/v1/create-qr-code/?data=" + encodeURIComponent(document.getElementById("input").value) + "&size=150x150"
document.getElementById("DisplayBLock").style.display = "revert"
});
document.getElementById("downloadBTN").addEventListener("click", function () {
let imageURL = document.getElementById("display").src;
fetch(imageURL)
.then(function (response) {
return response.blob();
})
.then(function (image) {
let downloadLink = document.createElement("a");
downloadLink.href = URL.createObjectURL(image)
downloadLink.download = "QRCode.png";
downloadLink.click();
});
});
document.getElementById("copyBTN").addEventListener("click", function () {
let imageURL = document.getElementById("display").src;
fetch(imageURL)
.then(function (response) {
return response.blob();
})
.then(function (image) {
navigator.clipboard.write([
new ClipboardItem({
[image.type]: image
})
])
});
});