~rleek/website

ref: 34102447e560e8accb4f0ebac1c37f8cf0da694d website/scan.html -rw-r--r-- 1.1 KiB
34102447rleek happy halloween 1 year, 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<!DOCTYPE html>
<html>
    <head>
        <title>Scan</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta charset="utf-8">
    </head>

    <button id="btn-open-scanner">Open Scanner!</button>
    <h3>Result</h3>
    <p id="result"></p>

    <script type="text/javascript">
        window.onload = function() {
            var button = document.getElementById('btn-open-scanner');
            var result = document.getElementById('result');

            button.addEventListener('click', openScanner);

            function openScanner() {
                try {
                    if (typeof nativeApp !== 'undefined') {
                        nativeApp.scanBarcode();
                    } else {
                        webkit.messageHandlers.barcodeScanner.postMessage({});
                    }
                } catch (e) {
                    alert(JSON.stringify(e));
                }
            }

            window.onBarcodeScanned = function(barcode) {
                result.innerText = barcode;
            }
        }
    </script>
</html>