-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
19 lines (17 loc) · 791 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const input = document.querySelector("input")
const btnGenerator = document.getElementById("generator")
const bntDownload = document.getElementById("download")
const imgQRCode = document.getElementById("qrCodeImg")
btnGenerator.addEventListener("click", () => {
const qrCode = `http://api.qrserver.com/v1/create-qr-code/?data=${input.value}!&size=250x250!&color=BE3455`
imgQRCode.src = qrCode
imgQRCode.alt = 'QR Code gerado a partir do input que foi inserido no campo de entrada'
})
bntDownload.addEventListener('click', async () => {
const response = await fetch(imgQRCode.src)
const blob = await response.blob()
const downloadLink = document.createElement('a')
downloadLink.href = URL.createObjectURL(blob)
downloadLink.download = 'qrcode.jpg'
downloadLink.click()
})