Home News DOC Class DL Others Rice
Class  >  jsexecutor  >  SetData(string)
jsexecutor class : SetData(string) method

Description

Sets a string to JavaScript.

Syntax

instance.SetData(string)

Arguments

ClassNameDescription
stringdataJavaScriptに渡すデータ。

Return value

None.

Sample code

1:

window w;

2:

jsexecutor jse = w.CurrentJSExecutor;

3:

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(). It is as follows.


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


GetData() 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()

Receives a string data from Rice in JavaScript.

window.cooker.external.SetData(data)

Sends a string data from JavaScript to Rice.

window.cooker.external.Notice(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(), but is also assigned to window.cooker.data.

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

Links for reference

None.

Copyright © Rice All rights reserved.