Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Auto-redirect #106

Closed
mwambajoshua opened this issue Sep 4, 2020 · 2 comments
Closed

[Feature Request] Auto-redirect #106

mwambajoshua opened this issue Sep 4, 2020 · 2 comments

Comments

@mwambajoshua
Copy link

Hey, pardon me for the the dumb question. I there a way to make the scanner automatically redirect once it has decoded the qr url?

@mebjas
Copy link
Owner

mebjas commented Sep 4, 2020

Interesting feature request, I would like to prototype this and get back to you.

Thanks for raising this.

@mebjas
Copy link
Owner

mebjas commented Sep 4, 2020

for now, you can do this

function validURL(str) {
  var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
    '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
    '((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
    '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
    '(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
    '(\\#[-a-z\\d_]*)?$','i'); // fragment locator
  return !!pattern.test(str);
}

function onScanSuccess(qrCodeMessage) {
  if (validURL(qrCodeMessage)) {
    window.location.href = qrCodeMessage;
  }
}

var html5QrcodeScanner = new Html5QrcodeScanner(
	"qr-reader", { fps: 10, qrbox: 250 });
html5QrcodeScanner.render(onScanSuccess);

@mebjas mebjas closed this as completed Jun 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants