Paul Smith
Paul Smith

Reputation: 173

Generate QR code on page load

So i'm trying to generate a QR code on page load so people don't have to browse through my website on their mobile to get to one page. The code I have is:

<script>
function process()
{
var url=" https://api.qrserver.com/v1/create-qr-code/?size=150x150&data==" + window.location.href;
}
</script>
<body onload="process()">
</body>

And i'm not too sure where i'm going wrong with this ? It would be great if someone could point out the mistake please.

Thanks!

Upvotes: 1

Views: 1294

Answers (1)

user2417483
user2417483

Reputation:

You might be generating the QR code but you are not displaying, you need to put the image somewhere on the page -the following is only a guide

<script>
function process()
{
   var url=" https://api.qrserver.com/v1/create-qr-code/?size=150x150&data==" + window.location.href;
   document.getElementById('QRCode').src = url;
}
</script>
<body onload="process()">
   <img src='' id='QRCode' ...>
</body>

Upvotes: 2

Related Questions