1. Enter the full URL you want to shorten in the text box below.
2. Click the "Shorten URL" button.
3. Your shortened URL will appear below along with options to copy, share, view analytics, or delete it.
// Generate QR Code
generateQRCode(linkId);
} else {
document.getElementById("result").innerHTML = "Error: Could not create short URL.";
}
})
.catch(error => {
document.getElementById("result").innerHTML = "An error occurred. Please try again.";
console.error("Error:", error);
});
// Clear input field
document.getElementById("linkinput").value = "";
};
function generateQRCode(linkId) {
const options = {
method: 'POST',
headers: {
accept: 'image/png',
'content-type': 'application/json',
Authorization: 'pk_bNswKwnrLVD9Ud5c' // Replace with your actual API key
},
body: JSON.stringify({ type: 'png' })
};
fetch(`https://api.short.io/links/qr/${linkId}`, options)
.then(res => {
if (!res.ok) {
throw new Error("Failed to generate QR code: " + res.statusText);
}
return res.blob(); // Get the QR code as a blob
})
.then(blob => {
const url = URL.createObjectURL(blob); // Create a URL for the blob
const qrCodeImg = ``;
document.getElementById("qrCodeContainer").innerHTML = qrCodeImg; // Display the QR code
})
.catch(err => {
console.error("Error generating QR code:", err);
document.getElementById("qrCodeContainer").innerHTML = "Failed to generate QR code. Please check the console for details.";
});
}