jsexecutor class : GetData() method

Description

Returns a string set in JavaScript.

Syntax

instance.GetData()

Arguments

None.

Return value

ClassDescription
stringThe string set in JavaScript.

Sample code

1:

jsexecutor jse; // For Main-browser

2:

string fromJavaScript = jse.GetData(); // It gets a string which is set in JavaScript.

Notes

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


To set communication data with JavaScript, executes the following JavaScript code.


window.cooker.external.SetData(token, 'example data');


window.cooker.external.SetData(token,data) is an asynchronous function. Following Rice code may not work as expected.


jsexecutor jse; // For Main-browser

jse.Execute("window.cooker.external.SetData(token, 'example data');");

string fromJavaScript = jse.GetData(); // Probably from JavaScript's value is not "example data".


Perhaps the value of the fromJavaScript will not be "example data". This is because Rice calls GetData() before the asynchronous function, SetData(token, 'example data'), completes in JavaScript.

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.