Skip to content

How to Execute Custom Functions Inside a WebView

Camilo edited this page Jul 27, 2020 · 1 revision

In this example (Based on Code by DAN) we are defining a custom function that calls the window.history.back()
method inside the $webcontainer webview. Using the $agent.request API.

This method will be executed when the layer label is clicked. The $agent.response() is needed in order to continue the normal flow of events.

We are using Arrow Functions to simplify the syntax.

Tip: You can also trigger a reload using location.reload() or any JS browser function.

Note: Note that we are not using templates ({}).

{
    "$jason": {
        "head": {
            "title": "History Go Back",
            "description": "Triggers a History Back on Button Press",
            "actions": {
                "navigate_back": {
                    "type": "$agent.request",
                    "options": {
                        "id": "$webcontainer",
                        "method": "(() => window.history.back(); $agent.response();)"
                    }
                }
            }
        },
        "body": {
            "layers": [
                {
                    "type": "label",
                    "text": "<",
                    "style": {
                        "size": "45",
                        "top": "100%-50",
                        "left": "0",
                        "align": "center",
                        "width": "20%",
                        "color": "#ffffff",
                        "background":"#2C2C2C"
                    },
                    "action": {
                        "trigger": "navigate_back"
                    }
                }
            ],
            "background": {
                "type": "html",
                "url": "https://www.google.com",
                "action": {
                    "type": "$default"
                }
            }
        }
    }
}
Clone this wiki locally