summaryrefslogtreecommitdiff
path: root/examples/qmlapp/index.html
blob: f62a3863a7ae9f6f37d5a8a0931cda849b0aa22b (plain)
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
<html>
    <head>
        <script>
            document.write('<script src="' + (/[?&]webChannelBaseUrl=([A-Za-z0-9\-:/]+)/.exec(location.search)[1]) + '/webchannel.js/createWebChannel"><' + '/script>');
            function output(x)
            {
                document.querySelector("#out").innerHTML += x + "<br/>";
            }
        </script>
        <script>
            window.onload = function() {
                createWebChannel(function(c) {
                    c.subscribe(
                        "foobar",
                        function(message) {
                            output(message);
                        }
                    );
                    window.send = function() {
                        c.exec(
                            JSON.stringify({a:"This is a request from HTML"}),
                            function(response) {
                                output(JSON.parse(response).b);
                            }
                        );
                    };
                    window.send();
                });
            };
        </script>
    </head>
    <body>
    <a href="javascript:send()">Go</a>
    <div id="out"></div>
    </body>
</html>