Home News DOC Class DL Others Rice
Class  >  jsexecutor  >  GetData()
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:

window w;

2:

jsexecutor jse = w.CurrentJSExecutor;

3:

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('example data');


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


window w;

jsexecutor jse = w.CurrentJSExecutor;

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

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


Perhaps the value fromJavaScript will not be "example data". This is because Rice calls GetData() before the asynchronous function, SetData('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()

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.