-1

Instead of opening an alert in the following Javascript code I want to redirect to a URL where the URL is imported from a QR-Code scan but sadly am no good with Javascript. Any help?

<script type="text/javascript" charset="utf-8">
function scanCode(){
        cordova.plugins.barcodeScanner.scan(
          function (result) {
              setTimeout(function() {alert('Very good. ' + result.text);}, 500);
          }, 
          function (error) {alert("Scanning failed: " + error);
          }
       );
    }
</script>
Jørgen R
  • 10,568
  • 7
  • 42
  • 59
Lutz
  • 1
  • 1
  • instead of alert(), have `window.location=result.text`? – Marc B Nov 13 '14 at 17:05
  • A friendly tip: The answer to your question could be found be found very easily by googling "javascript redirect to url" or something along those lines. It's best to look for the answer yourself before posting to SO – Casey Rule Nov 13 '14 at 17:15

1 Answers1

0

Version with a redirection as an HTTP redirect :

<script type="text/javascript" charset="utf-8">
function scanCode(){
        cordova.plugins.barcodeScanner.scan(
          function (result) {
              setTimeout(function() {windows.location.replace(result.text);}, 500);
          }, 
          function (error) {alert("Scanning failed: " + error);
          }
       );
    }
</script>   

Version with a redirection as clicking on a link :

<script type="text/javascript" charset="utf-8">
function scanCode(){
        cordova.plugins.barcodeScanner.scan(
          function (result) {
              setTimeout(function() {windows.location.href(result.text);}, 500);
          }, 
          function (error) {alert("Scanning failed: " + error);
          }
       );
    }
</script>
Veve
  • 6,643
  • 5
  • 39
  • 58