'Using a QRCode scanner in an inappbrowser with cordova and MVC

I have to make a qrcode scanner for a mvc application that is embedded in cordova as an in app browser. So far I can scan a qrcode in cordova app:

document.addEventListener('deviceready', onDeviceReady, false);

function onDeviceReady() {
    const scanBtn = document.querySelector(".scan-btn");
    scanBtn.addEventListener("click", scan);

    function scan(){
        cordova.plugins.barcodeScanner.scan(
            function(result){
                if(!result.cancelled){
                    if(result.format == "QR_CODE"){
                        var value = result.text;
                        alert("Your code is " + value);
                    }
                }
            },
            function(error){
                alert("Scan failed " + error);
            }
        )
    }

    window.open = cordova.InAppBrowser.open;
    var ref = window.open(url, '_self ', 'location=no');
    ref.addEventListener("message", (params) => {
        alert(params.data.my_message);
    });
}

However I don't know how to make a request in mvc app to cordova app to fire a click event to open the scanner and scan the qrcode and then return the value scanned to mvc app. How can I do this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source