JavaScript

Inherits:Object

Singleton that connects the engine with the browser's JavaScript context in HTML5 export.

Description

The JavaScript singleton is implemented only in the HTML5 export. It's used to access the browser's JavaScript context. This allows interaction with embedding pages or calling third-party JavaScript APIs.

Note: This singleton can be disabled at build-time to improve security. By default, the JavaScript singleton is enabled. Official export templates also have the JavaScript singleton enabled. SeeCompiling for the Web in the documentation for more information.

Tutorials

Methods

JavaScriptObject

create_callback(Object object,String method)

Variant

create_object(String object, ...)vararg

void

download_buffer(PoolByteArray buffer,String name,String mime="application/octet-stream")

Variant

eval(String code,bool use_global_execution_context=false)

JavaScriptObject

get_interface(String interface)

Method Descriptions

Creates a reference to a script function that can be used as a callback by JavaScript. The reference must be kept until the callback happens, or it won't be called at all. SeeJavaScriptObject for usage.


Creates a new JavaScript object using thenew constructor. Theobject must a valid property of the JavaScriptwindow. SeeJavaScriptObject for usage.


Prompts the user to download a file containing the specifiedbuffer. The file will have the givenname andmime type.

Note: The browser may override theMIME type provided based on the filename's extension.

Note: Browsers might block the download ifdownload_buffer is not being called from a user interaction (e.g. button click).

Note: Browsers might ask the user for permission or block the download if multiple download requests are made in a quick succession.


Execute the stringcode as JavaScript code within the browser window. This is a call to the actual global JavaScript functioneval().

Ifuse_global_execution_context istrue, the code will be evaluated in the global execution context. Otherwise, it is evaluated in the execution context of a function within the engine's runtime environment.


Returns an interface to a JavaScript object that can be used by scripts. Theinterface must be a valid property of the JavaScriptwindow. The callback must accept a singleArray argument, which will contain the JavaScriptarguments. SeeJavaScriptObject for usage.