DEV Community

Cover image for How to use QR Code Generator API! With JS!
Mafee7
Mafee7

Posted on

2 1

How to use QR Code Generator API! With JS!

QR Code API By: Go QR

See API Docs:

http://goqr.me/api/

API Link

https://api.qrserver.com/v1/create-qr-code/

HTML

<input placeholder="data"> 
<button>Generate QR!</button><br><br>
<img src>
Enter fullscreen mode Exit fullscreen mode

Javascript

var parametersJson = {
    "size": 250, // Size of Qr Code
    "backgroundColor": "38-38-38", // Background Color Of Qr Code (In RGB)
    "qrColor": "255-255-255", // Color of Qr Code (In RGB)
    "padding": 2, // Padding 
    "data": "dev.to"
};

var parameters;

var btn = document.querySelector("button");
var img = document.querySelector("img");
var input = document.querySelector("input");

btn.addEventListener("click", function(){
    parametersJson.data = input.value || "dev.to";
    parameters = `size=${parametersJson.size}&bgcolor=${parametersJson.backgroundColor}&color=${parametersJson.qrColor}&qzone=${parametersJson.padding}&data=${parametersJson.data}` // Stitch Together all Paramenters
    img.src = `https://api.qrserver.com/v1/create-qr-code/?${parameters}` // Set Image URL To Link
});
Enter fullscreen mode Exit fullscreen mode

See Working Version:

https://jsfiddle.net/qcote16j/

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (2)

Collapse
 
somanathgoudar profile image
Somanath Goudar

Good One!

Collapse
 
saidi_ks profile image
Williams.N

nice one

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay