so i building a url shortner which takes the url from python and generates a QR code in along with the shortUrl, i am using jinja2template for the UI, as i am very new to JavaScript the below code is mostly copied from Youtube and Internet.
This is the class which will show the converted shortUrl and will have a copy link button next o it
<div class = "result__container">
<div class = "shorturl">
<div id="qrcode"></div>
</div>
<div>
<button onclick = "copyLink()">Copy Link</button>
</div>
</div>
This is the logic create the qr code I am using qrcode.min.js here to create the qrcode
<script src="https://cdn.jsdelivr.net/gh/davidshimjs/qrcodejs/qrcode.min.js"></script>
<script>
const qrcode = new QRCode(document.getElementById('qrcode'), {
text: response.shortUrl,
width: 128,
height: 128,
colorDark : '#000',
colorLight : '#fff',
correctLevel : QRCode.CorrectLevel.H
});
xhr.onload = function () {
const response = JSON.parse(this.responseText);
console.log(this.status);
console.log(response);
if(this.status ==200){
resultContainer.style.display = "flex";
shortUrl.innerHTML = `SHORT URL :- <a href=${response.shortUrl}>${response.shortUrl}</a>`
}
else{
alert(`An error occurred, ${response.detail}`)
}
};