Functions for creating and controlling webviews to show HTML pages or evaluate JavaScript. These API:s only exist on mobile platforms.

To use this library in your Defold project, add the following URL to your game.project dependencies:

https://github.com/defold/extension-webview/archive/master.zip

Static methods

staticcreate<T>(callback:(T, WebviewId, WebviewRequestId, WebviewCallbackType, WebviewCallbackData) ‑> Void):WebviewId

Creates a webview instance.

It can show HTML pages as well as evaluate Javascript. The view remains hidden until the first call.

On iOS, the callback will never get a webview.CALLBACK_RESULT_EVAL_ERROR, due to the iOS SDK implementation.

Parameters:

callback

A callback which receives info about finished requests taking the following parameters self - the calling script webview_id - the webview id request_id - the request id type - the type of the callback * data - the callback value ''data''

Returns:

The id number of the webview

staticdestroy(webview_id:WebviewId):Void

Destroys an instance of a webview

Parameters:

webview_id

The webview id (returned by the Webview.create call)

staticeval(webview_id:WebviewId, code:String):WebviewRequestId

Evaluates javascript in a webview.

Evaluates java script within the context of the currently loaded page (if any). Once the request is done, the callback (registered in Webview.create) is invoked. The callback will get the result in the data["result"] field.

Parameters:

webview_id

The webview id

code

The java script code to evaluate

Returns:

The id number of the request

staticis_visible(webview_id:WebviewId):Int

Gets the visibility state of the webview.

Parameters:

webview_idThe

webview id (returned by the Webview.create call)

Returns:

Returns 0 if not visible, 1 if it is visible

staticopen(webview_id:WebviewId, url:String, options:WebviewOpenOptions):WebviewRequestId

Open a page using an url.

Opens a web page in the webview, using an url. Once the request is done, the callback (registered in Webview.create) is invoked.

Parameters:

webview_id

The webview id

url

The url to open

options

Options for the request

Returns:

The id number of the request

staticopen_raw(webview_id:WebviewId, html:String, options:WebviewOpenOptions):WebviewRequestId

Open a page using html.

Opens a web page in the webview, using html data. Once the request is done, the callback (registered in Webview.create) is invoked.

Parameters:

webview_id

The webview id

html

The html data to display

options

Options for the request

Returns:

The id number of the request

staticset_position(webview_id:WebviewId, x:Int, y:Int, width:Int, height:Int):Void

Sets the position and size of the webview.

Parameters:

webview_id

The webview id

x

The x position of the webview

y

The y position of the webview

width

The width of the webview (-1 to match screen width)

height

The height of the webview (-1 to match screen height)

staticset_visible(webview_id:WebviewId, visible:Int):Void

Shows or hides a web view.

Parameters:

webview_id

The webview id (returned by the Webview.create call)

visible

If 0, hides the webview. If non zero, shows the view.