summaryrefslogtreecommitdiff
path: root/examples/qmlapp/index.html
blob: 4f4593cafcea483d5026b5a097faeb56b78543ec (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
<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript" src="qrc:///qwebchannel/webchannel.js"></script>
        <script type="text/javascript">
            function output(x)
            {
                document.querySelector("#out").innerHTML += x + "<br/>";
            }
            window.onload = function() {
                var baseUrl = (/[?&]webChannelBaseUrl=([A-Za-z0-9\-:/]+)/.exec(location.search)[1]);
                new QWebChannel(baseUrl, function(c) {
                    c.subscribe(
                        "foobar",
                        function(message) {
                            output(message);
                        }
                    );
                    window.send = function() {
                        c.exec(
                            {a:"This is a request from HTML"},
                            function(response) {
                                output(response.b);
                            }
                        );
                    };
                    window.send();
                });
            };
        </script>
    </head>
    <body>
    <a href="javascript:send()">Go</a>
    <div id="out"></div>
    </body>
</html>