Send message from webviewer to app

jared
Thu, 08 Oct 2020 20:47:01 +0000
Free Templates, Designs, and Block Combinations

@kartik14 had a question about how to send a message from an HTML file to the app. I created this sample app and HTML file to demonstrate sending basic form data to the app in a JSON object

https://x.thunkable.com/copy/7e75833491183b2c3256ee8547691870





    <script src="https://thunkable.github.io/webviewer-extension/thunkableWebviewerExtension.js"
type="text/javascript">





Click to send a message to the app






    /* when the button is clicked, send a message to the app*/
    document.getElementById('messageButton').onclick = function () {

        //get values from input form
        var message = document.getElementById('myText').value
        var second = document.getElementById('other').value
        var third = document.getElementById('third').value

        /*create JSON object to neatly send data*/
        var obj = {
            "data1": message,
            "data2": second,
            "data3": third
        };

        /*send data to app*/
        ThunkableWebviewerExtension.postMessage(obj);
    }





6 posts - 3 participants