From 954d46f302c4a8c168d3075a387baaa789d436bc Mon Sep 17 00:00:00 2001 From: nd <git@notandy.de> Date: Fri, 26 Mar 2021 22:37:23 +0100 Subject: [PATCH] added url field --- index.html | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/index.html b/index.html index 3f7de55..ba0281b 100644 --- a/index.html +++ b/index.html @@ -14,25 +14,39 @@ } </style> <body> + <input id="text" name="text" placeholder="QR code content"> <div id="qrcode"></div> </body> <script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript" src="js/qrcode.min.js"></script> <script type="text/javascript"> - var qrcode; - function generateQR() { - qrcode = new QRCode(document.getElementById("qrcode"), location.hash.substring(1)); - } - $( document ).ready(function() { - generateQR(); - }); + var qrcode; + var elText; + function generateQR() { + url = elText.value; + if (!qrcode) { + qrcode = new QRCode(document.getElementById("qrcode"), url); + } else { + qrcode.clear(); + qrcode.makeCode(url); + } + } + + $( document ).ready(function() { + window.addEventListener('hashchange', function() { + elText.value = location.hash.substring(1) + generateQR(); + }); + elText = document.getElementById("text"); + elText.oninput = function () { + window.location.hash = elText.value; + }; + elText.value = location.hash.substring(1); + + generateQR(); + }); - window.addEventListener('hashchange', function() { - qrcode.clear(); - qrcode.makeCode(location.hash.substring(1)); - }); - </script> <footer> -- GitLab