jsexecutor class : SetData(string) method

Description

Sets a string to JavaScript.

Syntax

instance.SetData(string)

Arguments

ClassNameDescription
stringdataData to pass.

Return value

None.

Sample code

1:

jsexecutor jse; // For Main-browser

2:

jse.SetData("example data"); // It sets a string to JavaScript environment.

Notes

Sets a string to the host object exposed to the JavaScript for JavaScript and Rice to communicate.


There are two ways to get a data in JavaScript.

The first way is to call window.cooker.external.GetData(token). It is as follows.


let data = await window.cooker.external.GetData(token); // This code will go well if it is in async function.


GetData(token) is an asynchronous function. The behavior of JavaScript asynchronous functions is not discussed here, but there are various restrictions on retrieving data.


The second way is to access window.cooker.data. It is as follows.


let data = window.cooker.data;


window.cooker.data is an object defined for easy transfer of data. When you call jsexecutor.SetData(string), the arguments are also assigned to window.cooker.data.

Host objects with the following names are exposed to JavaScript.


window.cooker.external

window.chrome.webview.hostObjects.external


The first object is alias of the second. it works the same whichever you use. Here, we explain the window.cooker.external as an example.

window.cooker.external has the following asynchronous functions.


window.cooker.external.GetData(token)

Receives a string data from Rice in JavaScript.

window.cooker.external.SetData(token,data)

Sends a string data from JavaScript to Rice.

window.cooker.external.Notice(token,data)

Fires Rice's jsexecutor.Notice event from JavaScript.


In addition to this, window.cooker.data is defined as an object for communication. Note: window.chrome.webview.hostObjects.data does not exist.

The argument of Rice's jsexecutor.SetData(string) is saved for handling in window.cooker.external.GetData(token), but is also assigned to window.cooker.data.

Since window.cooker.external.GetData(token) is an asynchronous function, there are various restrictions on receiving data, but window.cooker.data is just an object and can be easily accessed.


See JavaScript extensions. for host objects.

Links for reference

None.

Copyright © Cooker All rights reserved.